标签:
2 asdf adfsd 123abc abc123abc
3 6
1 2 #include<iostream> 3 #include<string.h> 4 #include<cmath> 5 using namespace std; 6 const int MAX = 1000; 7 int dp[MAX][MAX]={0}; 8 int main() 9 { 10 int len1,len2,n; 11 string str1,str2; 12 cin>>n; 13 while(n--) 14 { 15 cin>>str1>>str2; 16 len1=str1.length(); 17 len2=str2.length(); 18 for(int i=1;i<=len1;i++) 19 { 20 for(int j=1;j<=len2;j++) 21 { 22 if(str1[i-1]==str2[j-1]) 23 dp[i][j]=dp[i-1][j-1]+1; 24 else 25 dp[i][j]=max(dp[i-1][j],dp[i][j-1]); 26 } 27 } 28 cout<<dp[len1][len2]<<endl; 29 } 30 return 0; 31 } 32
标签:
原文地址:http://www.cnblogs.com/caterpillarofharvard/p/4228609.html