//DP入门题状态转移方程很容易想到 //关键是构建pre数组,多少有点像KMP里面构建的next数组 #include#include #define MAX 50100int a[MAX],pre[MAX],dp[MAX];int n;int main(){ int i,j,T,max; scanf("%d",&T); while(T--) { scanf("%d",&n); pre[1]=0; dp[1]=0; scanf("%d",&a[1]); max=0; for(i=2; i<=n; i++) { scanf("%d",&a[i]); if(a[i] =a[j] ; j=pre[j]) ; pre[i]=j; if(!pre[i]) dp[i]=0; else dp[i]=dp[pre[i]]+1; } max=dp[i]>max?dp[i]:max; }// for(i=1; i<=n; i++) printf("%d ",pre[i]); printf("\n");// for(i=1; i<=n; i++) printf("%d ",dp[i]); printf("\n"); printf("%d\n",max); } return 0;}