POJ 1159 Palindrome(DP)
2014-02-05 19:35
387 查看
真是无情,我都不知道为什么这样,感觉凑出来,n-原串和逆序串的LCS 就是答案。然后试一试的写了一发。就过了。。无情。。
dp用short定义就不会MTL 了。。。纪念一下自己稀里糊涂过了一题
dp用short定义就不会MTL 了。。。纪念一下自己稀里糊涂过了一题
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; char save[5005]; char res[5005]; short dp[5005][5005]; int main() { int n; while(scanf("%d",&n)!=EOF) { save[0]='#'; scanf("%s",save+1); for(int i=n;i>=1;i--) res[n-i+1]=save[i]; res[0]='@'; memset(dp,0,sizeof dp); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(save[i]==res[j]) { dp[i][j]=dp[i-1][j-1]+1; } else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); } } printf("%d\n",n-dp ); } return 0; }
相关文章推荐
- POJ 1159 Palindrome(区间dp)
- Palindrome - POJ 1159 dp
- poj1159——Palindrome(组成回文串的最少字符数,dp)
- 【转】POJ 1159 Palindrome【经典的DP回文问题】
- poj1159--Palindrome(dp:最长公共子序列变形 + 滚动数组)
- POJ 1159 Palindrome(基础DP)
- POJ-1159-Palindrome(简单dp)
- poj 1159 palindrome (dp)
- dp中滚动数组的应用:01背包、POJ 1159 Palindrome、多段图路径问题
- POJ 1159 Palindrome(区间DP/最长公共子序列+滚动数组)
- 【转】POJ 1159 Palindrome【经典的DP回文问题】
- poj1159--Palindrome(dp:最长公共子序列变形 + 滚动数组)
- POj 1159 Palindrome (dp)
- poj 1159 Palindrome 【DP】
- POJ---1159-Palindrome(01DP)
- POJ--1159:Palindrome (DP求最长公共子序列)
- POJ 1159-Palindrome(DP)
- DP::poj1159 Palindrome
- POJ 1159 Palindrome (滚动数组 DP)
- poj 1159 Palindrome (DP:LCS+滚动数组)