标签:
Input
Output
Sample Input
abcfbc abfcab programming contest abcd mnp
Sample Output
4 2 0
大意:最长公共子序列
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int dp[1000][1000]; int main(){ char s1[1000],s2[1000]; char t; while(~scanf("%s%s",s1,s2)){ memset(dp,0,sizeof(dp)); int n1 = strlen(s1); int n2 = strlen(s2); for(int i = 1 ; i <= n1;i++){ for(int j = 1;j <= n2; 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[n1][n2]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4321833.html