#include<iostream>
#include<string.h>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int table[1000][1000];
string s1, s2;
int dp()
{
memset(table, 0, sizeof(table));
for (int i = 1; i <= s1.size(); i++)
for (int j = 1; j <= s2.size(); j++)
{
table[i][j] = max(table[i - 1][j], table[i][j - 1]);
table[i][j] = max(table[i][j], table[i - 1][j - 1] + (s1[i - 1] == s2[j - 1] ? 1 : 0));
}
return table[s1.size()][s2.size()];
}
int main()
{
while (cin >> s1)
{
cin >> s2;
cout << dp() << endl;
}
return 0;
}
hdoj1159_Common Subsequence(dp)
最新推荐文章于 2020-04-13 10:58:43 发布