提交时间:2023-11-25 10:02:18

运行 ID: 112084

#include<bits/stdc++.h> using namespace std; const int maxn = 5005; string s, t; int dp[maxn][maxn]; int main (){ cin >> s; cin >> t; int ls = s.size(), lt = t.size(); for (int i = 1; i <= ls; i++){ for (int j = 1; j <= lt; j++){ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); if (s[i - 1] == t[j - 1]){ dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1); } } } cout << dp[ls][lt]; }