IDA*不解释
#include <cstdio>
int n, T, a[20], ans, limit;
void IDA(int dep){
int tot = 0;
for(int i = 0; i < n; ++i)
if(a[i + 1] != a[i] + 1)
++tot;
if(!tot){ if(dep < ans) ans = dep; return ; }
if(((tot + 2) / 3 + dep) > limit) return ;
for(int j = 1; j < n; ++j){
for(int i = 1; i + j - 1 <= n; ++i){
for(int k = i + 1; k + j - 1 <= n; ++k){
int b[20];
for(int o = 1; o <= n; ++o)
b[o] = a[o];
for(int o = k; o <= k + j - 1; ++o)
a[o] = b[o - k + i];
for(int o = i + j; o <= k + j - 1; ++o)
a[o - j] = b[o];
IDA(dep + 1);
for(int o = 1; o <= n; ++o)
a[o] = b[o];
}
}
}
}
int main(){
scanf("%d", &T);
while(T--){
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
ans = 6;
for(limit = 1; limit <= 4 && ans == 6; ++limit)
IDA(0);
if(ans != 6) printf("%d\n", ans);
else printf("5 or more\n");
}
}