LCS (scrolling array) POJ 1159 palindrome

Source: Internet
Author: User

Topic Portal

1 /*2 LCS nude title: length minus the maximum same length is the number of inserts to be inserted3 DP Array Two-dimensional open 5000 will be super memory, here is used to scroll the array,4 because in the calculation of LCS, I changes only 1, so you can scroll by 2 to take the remainder:)5 */6#include <cstdio>7#include <iostream>8#include <cstring>9#include <algorithm>Ten#include <string> One using namespacestd; A  - Const intMAXN = 5e3 +Ten; - Const intINF =0x3f3f3f3f; the intdp[2][MAXN]; - strings, SS; -  - intLCS (intN) + { -     intx =0; +      for(intI=1; i<=n; ++i) A     { atx =1-x; -          for(intj=1; j<=n; ++j) -         { -             if(ss[i-1] = = s[j-1]) -             { -DP[X][J] = dp[1-x][j-1] +1; in             } -             Else to             { +DP[X][J] = max (dp[x][j-1], dp[1-X] [j]); -             } the         } *     } $ Panax Notoginseng     returnDp[x][n]; - } the  + intMainvoid)//POJ 1159 palindrome A { the #ifndef Online_judge +Freopen ("1159.in","R", stdin); -     #endif $  $     intN; -      while(~SCANF ("%d", &N)) -     { theMemset (DP,0,sizeof(DP)); -CIN >>SS;Wuyis =SS; the Reverse (S.begin (), S.end ()); -  Wu         intres =LCS (n); -printf ("%d\n"Nres); About     } $  -     return 0; -}

LCS (scrolling array) POJ 1159 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.