UVA 10405最长公共子序列

裸最长公共子序列,直接贴代码

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<string.h>
 5 using namespace std;
 6 
 7 int dp[1000][1000];
 8 char str1[1000],str2[1000];
 9 
10 int main()
11 {
12     int len1,len2;
13     while(gets(str1)&&gets(str2))
14     {
15         memset(dp,0,sizeof(dp));
16         len1=strlen(str1);
17         len2=strlen(str2);
18         for(int i=0;i<len1;i++)
19             for(int j=0;j<len2;j++)
20             {
21                 if(str1[i]==str2[j])
22                     dp[i+1][j+1]=dp[i][j]+1;
23                 else
24                     dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
25             }
26         cout<<dp[len1][len2]<<endl;
27     }
28     return 0;
29 }
原文地址:https://www.cnblogs.com/pter/p/5409953.html