题目
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int f[N][N];
char A[N], B[N];
int main()
{
int n, m;
cin >> n >> m;
cin >> A+1 >> B+1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(A[i] == B[j]) f[i][j] = f[i-1][j-1] + 1;
else f[i][j] = f[i-1][j-1];
f[i][j] = max(f[i][j], f[i-1][j]);
f[i][j] = max(f[i][j], f[i][j-1]);
}
}
cout << f[n][m];
}