Title Source: Several series of stories--the formation of Perfect II
Serie A champion: China
Thinking: In the Manacher break guarantee non-strict reduction can be
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn = 100110; int A[maxn<<1];int b[maxn<<1];int dp[maxn<<1];int manacher (int n) {int maxlen = 0, id, ans = 0;for (int i = 1; I < n; i++) {if (MaxLen > i) dp[i] = min (dp[id*2-i], maxlen-i); Elsedp[i] = 1;int flag = 0, x = 1;if (a[i]! = 1) {flag = 1;x = A[i]; }while (A[i+dp[i]] = [A[i-dp[i]]) {if (a[i+dp[i]] = 1) dp[i]++;else{if (!flag) {x = A[i+dp[i]];DP [i]++;flag = 1;} Else{if (A[i+dp[i]] > x) break;x = a[i+dp[i]];dp [i]++;}}} if (Dp[i]+i > maxlen) {id = I;maxlen = dp[i]+i;} if (ans < dp[i]) ans = dp[i];} return ans-1;} int main () {int t;scanf ("%d", &t), while (t--) {int n;scanf ("%d", &n), a[0] = -1;a[1] = 1;for (int i = 1; I <= N; i++ {scanf ("%d", &a[i<<1]); a[i<<1|1] = 1;} n = n*2+2;a[n] = 2;printf ("%d\n", Manacher (n));} return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
HDU 4513 elder Brothers Series story--form Perfect II Manacher seek longest palindrome