BZOJ2565 longest Double palindrome string

Source: Internet
Author: User

Description sequence and reverse order read the exact same string called Palindrome string. For example, ACBCA is a palindrome string, and ABC is not (ABC's order is "ABC", Reverse is "CBA", not the same).
Enter the string s of length n, to find the longest double palindrome t of S, you can divide t into two parts x, Y, (| x|,| y|≥1) and X and Y are palindrome strings. Input

a line of string s consisting of lowercase English letters.

The output line is an integer representing the length of the longest double palindrome string. Sample InputBaacaabbacabb
Sample Output12
HINT

Sample Description

The string Aacaabbacabb starting from the second character can be divided into two parts, AACAA and Bbacabb, and both are palindrome strings.

For 100% of data, 2≤| S|≤10^5


2015.4.25 New Plus Data group

Source

2012 National Training Team Round 1 day2

The water of Pam, the pros and cons of each position to the left and right of the longest palindrome string length, and then sweep again can be
#include <cstdio>#include<cctype>#include<queue>#include<cstring>#include<algorithm>#defineRep (s,t) for (int i=s;i<=t;i++)#defineren for (int i=first[x];i!=-1;i=next[i])using namespaceStd;inlineintRead () {intx=0, f=1;CharC=GetChar ();  for(;! IsDigit (c); C=getchar ())if(c=='-') f=-1;  for(; IsDigit (c); C=getchar ()) x=x*Ten+c-'0'; returnx*F;}Const intmaxn=100010;CharCH[MAXN];intF2[MAXN],G2[MAXN];structPAM {intCnt,last; intto[maxn][ -],L[MAXN],F[MAXN]; voidinit () {memset (To,0,sizeof(to)); memset (L,0,sizeof(l)); Memset (F,0,sizeof(f)); CNT=f[0]=1; l[1]=-1; last=0; }    voidExtendintCintNintt) {intp=Last ;  while(ch[n]!=ch[n-l[p]-1]) p=F[p]; if(!To[p][c]) {            intnp=++cnt,k=f[p];l[np]=l[p]+2;  while(ch[n]!=ch[n-l[k]-1]) k=F[k]; F[NP]=to[k][c];to[p][c]=NP; } Last=To[p][c]; if(!t) f2[n]=L[last]; Elseg2[n]=L[last]; }}sol;intMain () {scanf ("%s", ch+1);intN=strlen (ch+1), ans=0; Sol.init (); Rep (1, N) sol.extend (ch[i]-'a'I0); Sol.init (); Reverse (Ch+1, ch+n+1); Rep (1, N) sol.extend (ch[i]-'a'I1); Rep (2, N) Ans=max (ans,f2[i-1]+g2[n-i+1]); printf ("%d\n", ans); return 0;}
View Code

BZOJ2565 longest Double palindrome string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.