POJ - 1458 - Common Subsequence (LCS)
2015-05-04 21:52
411 查看
题目传送:Common Subsequence
思路:LCS
AC代码:
思路:LCS
AC代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <vector> #include <map> #include <set> #include <deque> #include <cctype> #define LL long long #define INF 0x7fffffff using namespace std; char s[205]; char t[205]; int dp[205][205]; int main() { while(scanf("%s %s", s + 1, t + 1) != EOF) { int ls = strlen(s + 1); int lt = strlen(t + 1); memset(dp, 0, sizeof(dp)); for(int i = 1; i <= ls; i ++) { for(int j = 1; j <= lt; j ++) { if(s[i] == t[j]) { dp[i][j] = dp[i - 1][j - 1] + 1; } else { dp[i][j] = max(dp[i-1][j], dp[i][j-1]); } } } cout << dp[ls][lt] << endl; } return 0; }
相关文章推荐
- POJ 1458 Common Subsequence(LCS)
- Poj 1458 Common Subsequence(LCS)
- POJ1458 Common Subsequence LCS问题入门题[DP]
- HDU 1159 & POJ 1458 Common Subsequence(LCS 最长公共子序列O(nlogn))
- poj-1458-Common Subsequence(LCS)
- Poj 1458 Common Subsequence(LCS)
- POJ1458 Common Subsequence LCS问题入门题[DP]
- POJ 1458--Common Subsequence【LCS】
- hdu 1159 && POJ 1458Common Subsequence(LCS)
- POJ 1458 Common Subsequence(LCS)
- poj 1458 Common Subsequence(LCS)
- poj 1458 Common Subsequence(lcs模板)
- POJ 1458 && HDU 1159 Common Subsequence(LCS)
- Poj 1458 Common Subsequence(LCS)
- POJ 1458-Common Subsequence(线性dp/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(LCS)