Time limit:20 Sec Memory limit:128 MB
submit:2079 solved:899 Description
Consider a string s that contains only the lowercase Latin alphabet. We define the "out" of a substring t of s
The present value is the number of occurrences of T in s multiplied by the length of T. Please find out the most in all palindrome strings of S
Large occurrence value.
Input
Enter only one row for a non-empty string s that contains only a lowercase letter (A-Z).
Output
Outputs an integer that is the largest occurrence of a palindrome substring.
Sample Input"Sample Input L"
Abacaba
"Sample input 2]
Www
Sample Output"Sample Output L"
7
Sample Output 2]
4
HINT
A string is a palindrome when and only if it reads from left to right and reads from right to left exactly the same.
In the first example, there are 7 palindrome substrings: A,b,c,aba,aca,bacab,abacaba, wherein:
A appears 4 times with a value of 4:1:1=4
B appears 2 times with a value of 2:1:1=2
C appears 1 times with a value of l:1:l=l
ABA appears 2 times with a value of 2:1:3=6
ACA appears 1 times with a value of 1=1:3=3
Bacab appears 1 times with a value of 1:1:5=5
Abacaba appears 1 times with a value of 1:1:7=7
Therefore, the maximum palindrome string occurrence value is 7.
"Data size and scoring"
The data satisfies the 1≤ string length ≤300000.
Source
String Palindrome automatic Machine
In the Huang long blog, turned to this magical thing--palindrome automaton
Studied for half a day, this thing and ac automata, suffix automata somewhat similar (all automata), through the fail pointer in the tree jump to complete the matching string.
Palindrome automatic machine, each node represents a palindrome string, each to add a character to the automaton, the current total string update the longest palindrome suffix:
For example: Aoaueoqwelje Abababa, the longest palindrome suffix is abababa, if added a b,abababab is not a palindrome string, so along the fail pointer back to the longest palindrome suffix string ababa, (there is a b) +ababa+ (the newly added B) Can form a palindrome string, create a new node to represent it, and record the length and number of occurrences of the message.
Here is a detailed explanation http://blog.csdn.net/u013368721/article/details/42100363
So this is a template problem. Note that statistics are counted when the number of occurrences is counted, in order to accumulate the number of occurrences of fail pointing position
1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <vector>8 using namespacestd;9 Const intmxn=350100;Ten intRead () { One intx=0, f=1;CharCh=GetChar (); A while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} - returnx*F; the } - CharS[MXN]; - Long Longans=0; - structhwm{ + intt[mxn][ -]; - intFA[MXN]; + intL[MXN],SZ[MXN]; A intS,cnt,last; at voidinit () { -s=cnt=last=fa[0]=fa[1]=1; l[1]=-1; - return; - } - voidAddintCintN) { - intp=Last ; in for(; s[n-l[p]-1]!=s[n];p =fa[p]); - if(!T[p][c]) { to intnp=++cnt;l[np]=l[p]+2; + intk=Fa[p]; - while(s[n-l[k]-1]!=s[n]) k=Fa[k]; theFA[NP]=T[K][C];// *t[p][c]=NP; $ }Panax Notoginsenglast=T[p][c]; -++Sz[last]; the return; + } A voidsolve () { the for(inti=cnt;i;i--){ +sz[fa[i]]+=Sz[i]; - Long LongTmp= (Long Long) sz[i]*L[i]; $ if(Tmp>ans) ans=tmp; $ } - return; - } the }HW; - intMain () {Wuyi inti,j; thescanf"%s", s+1); - hw.init (); Wu intLen=strlen (s+1); - for(i=1; i<=len;i++) Hw.add (s[i]-'a', i); About hw.solve (); $printf"%lld\n", ans); - return 0; -}
Bzoj3676 [Apio2014] palindrome string