标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 40210 | Accepted: 16188 |
Description
Input
Output
Sample Input
abcfbc abfcab programming contest abcd mnp
Sample Output
4 2 0
Source
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> using namespace std; char str1[1001],str2[1001]; int dp[2][1001]; int l1,l2; int main() { // freopen("in.txt","r",stdin); while(~scanf("%s%s",str1,str2)){ memset(dp,0,sizeof(dp)); l1=strlen(str1);l2=strlen(str2); for(int i=0;i<l1;i++) for(int j=0;j<l2;j++) { if(str1[i]==str2[j]) dp[(i+1)&1][j+1]=max(dp[i&1][j]+1,max(dp[(i+1)&1][j],dp[i&1][j+1])); else dp[(i+1)&1][j+1]=max(dp[i&1][j+1],dp[(i+1)&1][j]); } printf("%d\n",dp[l1&1][l2]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/codeyuan/p/4279941.html