题意:给n个串,求最大公共子串。(1<=n<=5,每个串长度<=2000)
#includeusing namespace std;const int N=2005<<1;struct sam { int cnt, root, last, l[N], c[N][26], f[N], p[N], mx[N], mxl[N]; sam() { cnt=0; root=last=++cnt; } void add(int x) { int now=last, a=++cnt; last=a; l[a]=l[now]+1; for(; now && !c[now][x]; now=f[now]) c[now][x]=a; if(!now) { f[a]=root; return; } int q=c[now][x]; if(l[q]==l[now]+1) { f[a]=q; return; } int b=++cnt; memcpy(c[b], c[q], sizeof c[q]); l[b]=l[now]+1; f[b]=f[q]; f[q]=f[a]=b; for(; now && c[now][x]==q; now=f[now]) c[now][x]=b; } void build(char *s) { int len=strlen(s); for(int i=0; i
复习了下sam....