[bzoj3676][Apio2014]回文串 回文自动机(回文树)
2017-07-28 15:21
471 查看
3676: [Apio2014]回文串
Time Limit: 20 Sec Memory Limit: 128 MB[Submit][Status][Discuss]
Description
考虑一个只包含小写拉丁字母的字符串s。我们定义s的一个子串t的“出现值”为t在s中的出现次数乘以t的长度。请你求出s的所有回文子串中的最
大出现值。
Input
输入只有一行,为一个只包含小写字母(a -z)的非空字符串s。Output
输出一个整数,为逝查回文子串的最大出现值。Sample Input
【样例输入l】abacaba
【样例输入2]
www
Sample Output
【样例输出l】7
【样例输出2]
4
HINT
你们搞的这个回文自动机啊,亦可赛艇!
这个博客写的吼http://blog.csdn.net/u013368721/article/details/42100363
代码也很短啊
#include<iostream> #include<cstring> #include<cstdio> const int NSOI = 300000 + 5; typedef long long ll; ll ans; char s[NSOI]; int n,now,tot,cur,last,cnt[NSOI],fail[NSOI],ch[NSOI][26],len[NSOI]; int newnode( int x ){ len[tot] = x; return tot++; } int getfail( int x, int n ){ while( s != s[n-len[x]-1] ) x = fail[x]; return x; } ll Max( ll x, ll y ){ return x<y ? y : x; } int main(){ gets(s+1); s[0] = -1; newnode(0); newnode(-1); fail[0] = 1; for( n = 1; s ; n++ ){ int x = s -'a'; cur = getfail(last,n); if( !ch[cur][x] ){ now = newnode(len[cur]+2); fail[now] = ch[getfail(fail[cur],n)][x]; ch[cur][x] = now; } cnt[last=ch[cur][x]]++; } for( n = --tot; n > 1; n-- ) cnt[fail ]+=cnt ,ans=Max(ans,(ll)cnt *(ll)len ); printf("%lld", ans); return 0; }
相关文章推荐
- bzoj 3676: [Apio2014]回文串 manachar+后缀自动机+倍增(回文树)
- bzoj 3676: [Apio2014]回文串 回文自动机
- 【回文自动机】bzoj3676 [Apio2014]回文串
- 【APIO2014】回文串 jzoj 3654/洛谷 3649/bzoj 3676 回文树(回文自动机)
- [manacher 后缀自动机 || 回文自动机] BZOJ 3676 [Apio2014]回文串
- 【BZOJ3676】[Apio2014]回文串 【回文自动机】
- 【BZOJ3676】[Apio2014]回文串 回文自动机
- 回文自动机 模板 bzoj3676【Apio2014】回文串
- bzoj 3676: [Apio2014]回文串 (回文自动机)
- 【bzoj3676】[Apio2014]回文串 回文自动机
- BZOJ3676:[Apio2014]回文串(回文自动机)
- [回文自动机] BZOJ 3676: [Apio2014]回文串
- [BZOJ]3676: [Apio2014]回文串 回文自动机
- 【bzoj3676】[Apio2014]回文串 —— 回文自动机的学习
- bzoj 3676: [Apio2014]回文串 回文自动机
- BZOJ 3676: [Apio2014]回文串 回文自动机
- bzoj 3676: [Apio2014]回文串 -- 回文自动机
- [BZOJ3676][Apio2014]回文串(回文自动机)
- bzoj3676 [Apio2014]回文串(回文自动机)
- [回文自动机] BZOJ3676 [Apio2014] . 回文串