poj 1458 Common Subsequence(lcs)
2017-02-15 16:35
357 查看
题目链接:
http://poj.org/problem?id=1458题意:
求两个字符串的lcsAC代码
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; const int maxn = 1000; int dp[maxn][maxn]; char s[maxn]; char s1[maxn],s2[maxn]; int main() { while(gets(s)) { sscanf(s,"%s %s",s1,s2); int len1 = strlen(s1),len2 = strlen(s2); memset(dp,0,sizeof(dp)); for(int i = 1 ; i <= len1; i++) { for(int j = 1; j <= len2; j++) { if(s1[i-1] == s2[j-1]) { 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",dp[len1][len2]); } return 0; }
相关文章推荐
- poj 1458 Common Subsequence【LCS】
- Poj 1458 Common Subsequence【LCS】【dp】
- HDU/HDOJ 1159/POJ 1458 Common Subsequence(最长公共子序列LCS,滚动数组)
- poj 1458 Common Subsequence --- LCS模板
- poj 1458 Common Subsequence(LCS)
- 最长公共子序列(LCS, Longest Common Subsequence), POJ 1458
- POJ 1458 Common Subsequence 最长公共子序列(LCS)
- POJ 1458--Common Subsequence【LCS】
- POJ1458 Common Subsequence LCS问题入门题[DP]
- POJ 1458 Common Subsequence(LCS)
- poj1458-Common Subsequence(最长公共子序列,LCS)
- poj 1458 Common Subsequence(LCS)
- poj1458 Common Subsequence【LCS】
- POJ 1458-Common Subsequence(线性dp/LCS)
- HDU 1159 & POJ 1458 Common Subsequence 【LCS】
- POJ1458 Common Subsequence LCS问题入门题[DP]
- POJ 1458 Common Subsequence DP LCS 最长公共子序列
- POJ 1458 / HDU 1159 / Southeastern Europe 2003 Common Subsequence (DP&LCS)
- Poj 1458 Common Subsequence(LCS)
- HDU 1159 & POJ 1458 Common Subsequence(LCS 最长公共子序列O(nlogn))