POJ 1458 Common Subsequence——LCS
2017-09-01 12:24
465 查看
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 5000; char str1[maxn], str2[maxn]; int n, m, dp[maxn][maxn]; int main() { while (~scanf("%s %s", str1 + 1, str2 + 1)) { n = strlen(str1 + 1), m = strlen(str2 + 1); dp[0][0] = dp[0][1] = dp[1][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (str1[i] == str2[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", dp [m]); } return 0; }
相关文章推荐
- POJ 1458--Common Subsequence【LCS】
- POJ - 1458 - Common Subsequence (LCS)
- POJ:1458 Common Subsequence(LCS)
- poj 1458 Common Subsequence(LCS)
- POJ 1458 Common Subsequence(最长公共子序列LCS)
- POJ 1458-Common Subsequence(线性dp/LCS)
- POJ1458 Common Subsequence LCS问题入门题[DP]
- 最长公共子序列(LCS, Longest Common Subsequence), POJ 1458
- POJ1458 Common Subsequence LCS问题入门题[DP]
- POJ 1458 Common Subsequence(LCS)
- poj 1458 Common Subsequence【LCS】
- POJ 1458 Common Subsequence DP LCS 最长公共子序列
- poj - 1458 - Common Subsequence(LCS)
- HDU 1159 & POJ 1458 Common Subsequence 【LCS】
- HDU1159 && POJ1458 Common Subsequence (LCS)
- HDU/HDOJ 1159/POJ 1458 Common Subsequence(最长公共子序列LCS,滚动数组)
- POJ 1458 Common Subsequence(最长公共子序列LCS)
- poj 1458 Common Subsequence(LCS)
- POJ 1458 / HDU 1159 / Southeastern Europe 2003 Common Subsequence (DP&LCS)
- Poj 1458 Common Subsequence【LCS】【dp】