https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3807
#include<iostream>
#include<cstdio>
#define max(a,b) ((a)>(b)?(a):(b))
main(){
int t, n, i;
int s[100010];
int last[100010];
scanf("%d",&n);
while (n--){
scanf("%d",&t);
for (i = 0; i < t; i++){
scanf("%d",&s[i]);
last[s[i]] = 0;
}
int ans[100010] = {0};
last[s[0]] = 1;
ans[0] = 0;
for (i = 1; i < t; i++){
if (last[s[i]] != 0){
ans[i] = max(ans[i - 1], ans[last[s[i]]] + 1);
}
else
ans[i] = ans[i-1];
last[s[i]] = i;
}
printf("%d\n", ans[t-1]);
}
}
留言列表