#include <iostream>
using namespace std;
char s1[1024], s2[1024];
int dp[1024][1024];
int main()
{
while (cin >> s1 >> s2)
{
int len1 = strlen(s1), len2 = strlen(s2);
for (int i = 1; i <= len1; i++)
for (int j = 1; j <= len2; j++)
{
if (s1[i - 1] == s2[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
else
{
if (dp[i - 1][j] > dp[i][j - 1]) dp[i][j] = dp[i - 1][j];
else dp[i][j] = dp[i][j - 1];
}
}
cout << dp[len1][len2] << endl;
}
}
HDU1159 最长公共子序列
最新推荐文章于 2021-03-06 02:43:12 发布