后缀数组求最长回文串
#include
#include
#include
#include
using namespace std;
#define MAXN 2010
int dp[2010][30];
char r[MAXN],rr[MAXN];
int sa[MAXN];
int wa[MAXN],wb[MAXN],wv[MAXN],ws[MAXN];
int height[MAXN],rk[MAXN];
inline bool cmp(int *r,int a,int b,int len){return r[a]==r[b]&&r[a+len]==r[b+len];
}
void SA(int n,int m){int i,j,p,*x=wa,*y=wb,*t;for(i=0;i=0;i--)sa[--ws[x[i]]]=i;for(j=p=1;p=j)y[p++]=sa[i]-j;}for(i=0;i=0;i--)sa[--ws[wv[i]]]=y[i];for(t=x,x=y,y=t,x[sa[0]]=0,p=i=1;i}
void Height(int n){int i,j,k&#61;0;for(i&#61;0;i<&#61;n;i&#43;&#43;) //这里sa[0]为‘\0’开始的子串rk[sa[i]]&#61;i;for(i&#61;0;i}
int init(){int i,j,len;memset(height,0,sizeof(height));len&#61;strlen(rr);for(i&#61;0;i}
void st(int n){int i,j,p,q;for(i&#61;1;i<&#61;n;i&#43;&#43;)dp[i][0]&#61;i;for(j&#61;1;j<&#61;(int)(log((double)n)/log(2.0));j&#43;&#43;)for(i&#61;1;i&#43;(1<q)dp[i][j]&#61;dp[i&#43;(1<<(j-1))][j-1];elsedp[i][j]&#61;dp[i][j-1];}}
int RMQ_MIN(int i,int j){int tem;if(i>j){tem&#61;i;i&#61;j;j&#61;tem;}i&#43;&#43;; //交换后小的要加一int k&#61;(int)(log((double)(j-i&#43;1))/log(2.0));return min(height[dp[i][k]],height[dp[j-(1<}
void solve(int n){int i,j,ans&#61;0,s;st(n);for(i&#61;0;ians){ans&#61;j*2-1;s&#61;i-j&#43;1;}j&#61;RMQ_MIN(rk[i],rk[n-i]);if(j*2>ans){ans&#61;j*2;s&#61;i-j;}}for(i&#61;s;i}
int main(){int i,j,n;scanf("%s",rr);n&#61;init();SA(n&#43;1,130);Height(n);solve(n);
}