#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
const int MAX = 110, INF = 1<<30;
char str1[MAX], str2[MAX];
int dp[MAX][MAX] = {0};
int main()
{
while(scanf("%s %s", str1, str2) != EOF)
{
int max_len = 0;
int len1 = strlen(str1);
int len2 = strlen(str2);
for(int i=1; i<=len1; i++)
{
for(int j=1; j<=len2; j++)
{
if(str1[i-1] == str2[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
max_len = max(max_len, dp[i][j]);
}
}
printf("%d\n", max_len);
}
return 0;
}
【codeup墓地】1132: 最长公共子序列(动态规划)
最新推荐文章于 2022-06-23 11:43:57 发布