HDU 1159 Common Subsequence
2012-03-28 21:14
369 查看
LCS,动态规划基本题型...
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1159
代码如下:
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1159
代码如下:
#include <stdio.h> #include <string.h> char a[1000005], b[1000005]; int dp[10005][10005]; int lena, lenb; int max( int x, int y ) { return x>y ? x : y; } int LCS( int lena, int lenb ) { int len = max(lena, lenb); for( int i = 0; i <= len; i++ ) { dp[i][0] = 0; } for( int i = 1; i <= lena; i++ ) for( int j = 1; j <= lenb; j++ ) { if(a[i-1] == b[j-1]) dp[i][j] = dp[i-1][j-1] + 1; else dp[i][j] = max(dp[i-1][j],dp[i][j-1]); } return dp[lena][lenb]; } int main() { while(scanf("%s %s",a,b) == 2 ) { lena = strlen(a); lenb = strlen(b); printf("%d\n",LCS(lena,lenb)); } return 0; }
相关文章推荐
- HDU 1159 & POJ 1458 Common Subsequence(LCS 最长公共子序列O(nlogn))
- HDU 1159 Common Subsequence(DP最长公共子序列)
- HDU 1159 Common Subsequence(LCS)
- HDU-1159 Common Subsequence (线性dp 最长公共子串)
- HDU 1159 Common Subsequence(LCS)
- hdu 1159 && poj 1458 Common Subsequence (LCS)
- hdu 1159 Common Subsequence
- hdu 1159 Common Subsequence
- HDU-1159-Common Subsequence
- 【水:最长公共子序列】【HDU1159】【Common Subsequence】
- HDU 1159 Common Subsequence 公共子序列
- HDU 1159 Common Subsequence(最长公共子序列的长度)
- hdu 1159 Common Subsequence(动态规划:最长公共子序列)
- HDU1159 Common Subsequence
- HDU 1159 Common Subsequence (动规+最长公共子序列)
- HDU 1159 Common Subsequence
- HDU 1159 Common Subsequence
- hdu 1159 Common Subsequence (LCS)
- HDU 1159 Common Subsequence--最长公共子序列
- hdu 1159Common Subsequence(dp 最大不连续的子序列)