51Nod 1092 回文字符串 | 最长公共子序列变形
2017-09-05 16:02
645 查看
求字符串和其逆的最长公共子序列,需要添加的字符数就为长度-最长公共子序列长
#include "stdio.h" #include "string.h" #define maxn 1005 char s[maxn],s1[maxn]; int dp[maxn][maxn]; int main() { int n=0,i,j,len; scanf("%s",s); len=strlen(s); strcpy(s1,s); strrev(s1); for(i=0;i<len;i++) { for(j=0;j<len;j++) { if(s[i]==s1[j]) dp[i+1][j+1]=dp[i][j]+1; else dp[i+1][j+1]=dp[i+1][j]>dp[i][j+1]?dp[i+1][j]:dp[i][j+1]; } } printf("%d\n",len-dp[len][len]); }
相关文章推荐
- 51Nod-1092 回文字符串(最长公共子序列变形)
- 51nod 1092 回文字符串(区间dp)
- 51nod 1092 回文字符串 dp问题
- 51nod-【1092 回文字符串】
- 【51Nod】1092 - 回文字符串(LCS)
- nyoj 37 51nod oj 1092 回文字符串 【LCS变形】
- 51Nod-1092-回文字符串
- 51nod 1092 回文字符串 (添加几个变成回文)
- 51Nod 1092 回文字符串(LCS跟dp)
- 51nod 1092 回文字符串 LCS 或 区间dp
- 51nod 1092 回文字符串 (LCS_DP)
- 51nod 1092 回文字符串
- 51NOD 1092 回文字符串 LCS
- 51nod 1092 回文字符串
- LCS-51NOD-1092 回文字符串
- 51nod 1092 回文字符串
- 51nod 1092 回文字符串(LCS)
- 【51nod 1092 回文字符串】+ LCS
- 51nod 1092 回文字符串 【巧用 dp】
- 51nod 1092 回文字符串 (dp)