题目:3697. 回文子序列
题解:注意边读取边判断的时候,一定要把所有数据都读完!!!我之前看见别人的题解他们提到这点,我心里还有点想笑,寻思这不是新手刚开始会犯的错误么,emmmm,现在我又犯错误了,做题要谨慎!!!胆大心细!!!
另外:这题是求的回文子序列,也就是不是回文子串,不需要连续。说白了就是问是否存在两个相等的数,且其下标差>=2。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int ,int> PII;
const int N=1e5+10;
const int mod=100000007;
int main(){
int T;
cin>>T;
while(T--){
int n;
cin>>n;
int a[5010];
memset(a,0,sizeof a);
int t;
bool flag=0;
for(int i=1;i<=n;i++){
cin>>t;
if(!a[t]){
a[t]=i;
}else{
if(i-a[t]>=2){
flag=1;
}
}
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}