Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4513
Test instructions than the longest palindrome string more than a front of the person is lower than the person below this condition, so in p[i]++ time to judge S[i-p[i]]<=s[i-p[i]+2] on it;
Using the longest palindrome string algorithm manacher: Set a template on it;
#include <stdio.h>#include<string.h>#include<algorithm>using namespacestd;Const intN = 2e5+7;intP[n];intS[n];intManacher (intS[],intN) { intId=0, mx =0, ans =0; for(intI=2; i<n; i++) { if(MX >i) p[i]= Min (p[id*2-I.], mx-i); ElseP[i]=1; while(S[i+p[i] [= S[i-p[i]] && s[i-p[i]]<=s[i-p[i]+2] )///The condition to be satisfied is that the front is smaller than the following person so write;p[i]++; if(MX < p[i]+i) {mx= p[i]+i; Id=i; } ans=Max (ans, p[i]); } returnAns-1;}intMain () {intT, N; scanf ("%d", &T); while(t--) {scanf ("%d", &N); for(intI=0; i<n; i++) scanf ("%d", &S[i]); for(intI=n; i>=0; i--) {s[i+i+2] =S[i]; S[i+i+1] =0; } s[0] =1; intAns = manacher (S,2*n+2); printf ("%d\n", ans); }return 0;}
View Code
The story of the series--Perfect Formation II---hdu4513 (longest palindrome string manacher)