Ural 1297 palindrome "longest palindrome string"

Source: Internet
Author: User

Longest palindrome string Related data:

1. Violence Law2. Dynamic Planning3. Center Expansion4. Manacher Method http://blog.csdn.net/ywhorizen/article/details/6629268

http://blog.csdn.net/kangroger/article/details/37742639

The problem that comes up when you look at the suffix array

But it doesn't work. The suffix array is written = = used in a very violent way to get stuck in 1 s

Source Code:

#pragma COMMENT (linker, "/stack:16777216")//for C + + compiler#include <stdio.h> #include <iostream># Include <string> #include <algorithm>using namespace std;string A, res, TMP1, Tmp2;int ans;int main () {int I    , J, K, T, N, M;        while (Cin >> a) {ans = 1;        int len = A.size ();        BOOL flag = FALSE;            for (i = 0; i < len; ++i) {if (Len-i < ans) break;                for (j = len-i; J >= 1;--j) {tmp1 = A.substr (i, j);                TMP2 = TMP1; Reverse (Tmp1.begin (), Tmp1.end ()), a if (!flag) {if (Tmp1.compare (tmp2) = = 0 && J &                        gt;= ans) {flag = true;                        res = TMP1;                        Ans = j;                    Break  }} else{if (Tmp1.compare (tmp2) = = 0 && J > ans) {flag                        = true; res = TMP1;                        Ans = j;                    Break    }}}} cout << res << Endl; } return 0;}

531 MS is can be over = = but everyone with the suffix array is 15MS too, a little embarrassed AH

Ural 1297 palindrome "longest 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.