#pragma warning(disable :4996)
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include <stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
int dp[110][110] = { 0 };
string str1, str2;
while (cin >> str1 >> str2)
{
int len1 = str1.length(), len2 = str2.length();
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][j - 1], dp[i - 1][j]);
}
cout << dp[len1][len2]<<endl;
}
}
最长公共子序列
最新推荐文章于 2023-11-09 20:40:22 发布