提交时间:2023-11-25 09:06:56
运行 ID: 111918
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <cstring> using namespace std; const int MAXN = 1e3 + 1e2; string A, B; int f[MAXN][MAXN]; int main() { cin >> A >> B; int la = A.size(); int lb = B.size(); for (int i = 1;i <= la;i++) { for (int j = 1;j <= lb;j++) { f[i][j] = max(f[i - 1][j], f[i][j - 1]); if (A[i - 1] == B[j - 1]) f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1); } } printf("%d", f[la][lb]); return 0; }