1.动态规划 O()
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=101;
char str[maxn];
int dp[maxn][maxn];
int main(){
gets(str);
int len=strlen(str),ans=1;
// 初始化边界 dp[i][i]=1;dp[i][i+1]=(str[i]==str[i+1])?=1:0;
for(int i=0;i<len;i++){
dp[i][i]=1;
if(str[i]==str[i+1]&&i<len-1){
dp[i][i+1]=1;
ans=2;
}
}
//枚举长度
for(int L=3;L<=len;L++){
for(int j=0;j+L-1<len;j++){
//左端点 j,右端点 j+L-1
if(str[j]==str[j+L-1]&&dp[j+1][j+L-2]==1){
dp[j][j+L-1]=1;
ans=L;
}
}
}
//输出最大回文串最大长度
printf("%d\n",ans);
}
2.二分+字符串hash O()
3.Manacher O(n)
等复习到了再更新