文章
99
粉丝
120
获赞
8
访问
96.9k
#include<iostream>
using namespace std;
int dp[101][101];
int main()
{
string a,b;
memset(dp, 0, sizeof(dp));
cin >> a >> b;
int lena = a.size();
int lenb = b.size();
for (int i = 1;i <= lena;++i)
{
for (int j = 1;j <= lenb;++j)
{
if (a[i - 1] == b[j - 1])
{
dp[i][j] = dp[i - 1][j - 1] + 1;
}
else
{
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
cout << dp[lena][lenb] << endl;
}
登录后发布评论
暂无评论,来抢沙发