poj 1458 Common Subsequence(LCS)
2014-08-04 16:17
531 查看
//滚动数组写的,防止超内存 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int dp[2][1010];//dp[i][j]大小之于dp[i-1][j]有关 char s[1010],str[1010]; int lcs(int n,int m){ int i,j; for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ if(s[i-1]==str[j-1]) dp[i%2][j]=dp[(i-1)%2][j-1]+1; else dp[i%2][j]=max(dp[(i-1)%2][j],dp[i%2][j-1]); } } return dp[n%2][m]; } int main(){ int n,m,i,j; while(~scanf("%s%s",s,str)){ memset(dp,0,sizeof(dp)); n=strlen(s); m=strlen(str); printf("%d\n",lcs(n,m)); } return 0; }
相关文章推荐
- Poj 1458 Common Subsequence(LCS)
- Poj 1458 Common Subsequence(LCS)
- HDU 1159 & POJ 1458 Common Subsequence(LCS 最长公共子序列O(nlogn))
- poj - 1458 - Common Subsequence(LCS)
- poj-1458-Common Subsequence(LCS)
- POJ-1458 Common Subsequence 【LCS模板】
- POJ 1458 Common Subsequence(最长公共子序列LCS)
- HDU1159 && POJ1458 Common Subsequence (LCS)
- poj 1458 Common Subsequence(lcs模板)
- POJ 1458 && HDU 1159 Common Subsequence(LCS)
- POJ - 1458 - Common Subsequence (LCS)
- hdu 1159 && POJ 1458Common Subsequence(LCS)
- POJ 1458 Common Subsequence——LCS
- POJ 1458 Common Subsequence (zoj 1733 ) LCS
- poj1458--Common Subsequence--最长公共子序列LCS
- POJ 1458 Common Subsequence(LCS)
- POJ 1458 Common Subsequence (zoj 1733 ) LCS
- poj 1458 Common Subsequence (LCS模版题)
- POJ 1458 - Common Subsequence(LCS)
- POJ 1458 Common Subsequence(最长公共子序列LCS)