提交时间:2023-11-25 09:51:15

运行 ID: 112043

#include <bits/stdc++.h> using namespace std; int x[1005][1005]; int y[1005][1005]; int len(string a , string b) { int n = a.length(); int m = b.length(); for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { if(a[i - 1] == b[j - 1]) { x[i][j] = x[i - 1][j - 1] + 1; y[i][j] = 1; } else if(y[i - 1][j] >= x[i][j - 1]) { x[i][j] = x[i - 1][j]; y[i][j] = 2; } else { x[i][j] = x[i][j - 1]; y[i][j]= 3; } } } return x[n][m]; } int main() { string a , b; cin >> a >> b; cout << len(a , b); return 0; }