RT,悬关,求大佬指点一下
#include<bits/stdc++.h>
const int MAXN=5e7+16;
#define debug cout<<11111111111111111<<endl;
using namespace std;
int a[MAXN];
int ans=0,b[MAXN],vis[MAXN];
int h=1,cnt=1,k,n;
bool cmp1(int x,int y){return x>y;}
bool cmp2(int x,int y){return x<y;}
int H;
/*int prt(){
for(int i=1;i<=n;i++)cout<<a[i]<<" ";
cout<<endl;
cout<<"cnt:"<<cnt<<" "<<"H:"<<H<<" "<<"k:"<<k<<" "<<"h:"<<h<<" ";
cout<<endl;
}*/
int maxn=-MAXN;
int work(){
h=1;
H=b[h];
k=n;
cnt=0;
while(true){
H=b[h];
if(h<=k){
if(k==1)return (++cnt);
for(int i=h;i<k;i++)b[i]=b[i+1];
b[k]=0;
k--;
cnt++;
h=H;
}
else{
return cnt;
}
}
}
void dfs(int cur,int m){
if(cur==m){
ans=max(ans,work());
return ;
}
for(int i=1;i<=m;i++){
if(vis[a[i]]==0){
b[i]=a[i];
vis[a[i]]=1;
dfs(cur+1,n);
vis[a[i]]=0;
b[i]=0;
}
}
}
signed main(){
int t;
cin>>t;
while(t--){
ans=0;
cin>>n;
for(int i=1,x;i<=n;i++){
cin>>x;
a[i]=x;
b[i]=a[i];
}
dfs(0,n);
cout<<ans<<endl;
}
}
/*
2 3 4 5 0
h=2
*/