动态规划我不咋会,但是貌似机试必考吧....
#include<bits/stdc++.h>
using namespace std;
int dp[1010][1010];
int main(){
//dp问题
string str;
getline(cin,str);
int len=str.length();int ans=1;
//边界
for(int i=0;i<len;i++){
dp[i][i]=1;
if(i<len-1){
if(str[i]==str[i+1]){
dp[i][i+1]=1;
ans=2;
}
}
}
//状态转移方程
for(int L=3;L<=len;L++){
for(int i=0;i+L-1<len;i++){
int j=i+L-1;
if(str[i]==str[j]&&dp[i+1][j-1]==1){
dp[i][j]=1;
ans=L;
}
}
}
printf("%d\n",ans);
return 0;
}