POJ 1159 最少添加几个字母构成回文 DP
2017-02-12 12:56
253 查看
设原序列S的逆序列为S' ,则这道题目的关键在于, 最少需要补充的字母数 = 原序列S的长度 - S和S'的最长公共子串长度 http://www.cnblogs.com/en-heng/p/3963803.html #include<iostream> #include<queue> #include<algorithm> #include<stdlib.h> #include<stdio.h> #include<iomanip> #include<string.h> using namespace std; const int MAX=5005; int Len; int F[2][MAX]; char Str1[MAX]; char Str2[MAX]; int main() { cin.sync_with_stdio(false); while (cin>>Len) { cin>>Str1; for (int i=Len-1;i>=0;i--) Str2[i]=Str1[Len-1-i]; Str2[Len]='\0'; memset(F,0,sizeof(F)); int k=0,ans=0; for (int i=0;i<Len;i++) { for (int j=0;j<Len;j++) { if (Str1[i]==Str2[j]) { F[k][j]=F[k^1][j-1]+1; ans=max(ans,F[k][j]); } else F[k][j]=max(F[k^1][j],F[k][j-1]); } k=k^1; } cout<<Len-ans<<endl; } return 0; }
相关文章推荐
- POJ1159 Palindrome(dp加最少字母构成回文字符串)
- POJ 1159 添加最少几个字符可以成回文
- poj1159 —— 一个字符串,求最少插入几个字符可以组成回文
- POJ 1159 - Palindrome (DP 添加最少字符使s为回文串)
- 动态规划 加最少字符使字符串变回文 POJ 1159 short水过!
- 【转】POJ 1159 Palindrome【经典的DP回文问题】
- poj 1848 树形dp(添加最少的边每点都恰在一个圈中)
- POJ 1159 Palindrome 回文 DP
- POJ - 1159 Palindrome(dp-回文变形)
- UVA11548 DP计算添加多少元素可以构成回文字符串
- 【转】POJ 1159 Palindrome【经典的DP回文问题】
- POJ-1159(添加一些字符使得字符串对称)(DP+滚动数组)
- 动态规划 加最少字符使字符串变回文 POJ 1159 short水过!
- poj 1159 最少添加多少字符成回文串
- 【DP生成回文字符串的最小插入字符数】POJ 1159
- dp问题 添加最少的字符构成回文串
- poj1159——Palindrome(组成回文串的最少字符数,dp)
- POJ 3280 Cheapest Palindrome【DP之经典回文问题】
- 回文串 poj 1159
- poj&nbsp;1159&nbsp;Palindrome(DP)