Hdu 5340 three palindromes max palindrome string manacher

Source: Internet
Author: User

Three palindromesTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): Accepted submission (s): 21


Problem Descriptioncan We divided a given string S into three nonempty palindromes?

Inputfirst line contains a single integer t ≤ 20 which denotes the number of test cases.

For each test case, the there is a single line contains a string S which only consist of lowercase Chinese letters. 1 ≤ | s | ≤ 20000

Outputfor each case with the output the "Yes" or "No" in a.

Sample Input
2abcabaadada

Sample Output
YesNo
Test instructions, is to give a string, can be divided into three non-empty palindrome string. We can find the first and the third string, must be the largest palindrome string of a string, manacher to find the maximum palindrome string length, enumeration of the first and last, the middle of the direct judgment, the midpoint of the largest palindrome string whether it can be included. The degree of complexity is O (n * n).
#define N 110050#define M 100005#define maxn 205#define MOD 1000000000000000007int t,n,a,pri[n],ans,len,sn = 0,top[n],tai    L[n],pn,ln;bool Dp[n][4];p II seg[n];bool manacher (char str[],int len) {char tstr[n+n];    int p[n + N],L2 =0,mi;    tstr[l2++] = ' # ';        for (int i =0;i<len;i++) {tstr[l2++] = Str[i];    tstr[l2++] = ' # ';    } P[0] = 0;mi = 0;        for (int i = 1;i<l2;i++) {int mi2 = mi + mi-i;        if (mi + p[mi] >= i) p[i] = min (mi2-(Mi-p[mi]), p[mi2]);        else p[i] = 0;  if (p[i] = = 0 | |            MI2-P[MI2] = = Mi-p[mi]) {int maxx = p[i]+1;            while (I-maxx >= 0 && I+maxx < L2 && Tstr[i-maxx] = = Tstr[i+maxx]) {maxx++;        } P[i] = maxx-1;    } if (P[i] + i > p[mi] + mi) mi = i;    } int ans = -1;SN = 0;pn = LN = 0;        for (int i = 1;i < l2-1;i++) {if (i-p[i] = = 0) top[pn++] = i;    if (i + p[i] = = l2-1) tail[ln++] = i; } for (int i = 0;i < pn;i++) {for (int j = ln-1;j>=0;j--) {int S1 = Top[i] + p[top[i]] + 1,S2 = tail[j]-P            [Tail[j]]-1;            if (S1 > s2) break;            int mid = (S1 + s2)/2;        if (P[mid] >= mid-s1) return true;    }} return false; printf ("%d\n", ans);}            Char Str[n];int main () {while (S (T)!=eof) {while (t--) {SS (str);            len = strlen (str);            if (Manacher (Str,len)) printf ("yes\n");        else printf ("no\n"); }} return 0;}


Sourcebestcoder Round #49 ($)
Recommendhujie | We have carefully selected several similar problems for you:5342 5341 5339 5338 5337

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdu 5340 three palindromes max palindrome string manacher

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.