HDU 4513 elder Brothers Series story--form Perfect II Manacher seek longest palindrome

Source: Internet
Author: User

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

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.