提交时间:2023-11-27 13:48:44

运行 ID: 112614

#include<bits/stdc++.h> using namespace std; int dp[7005][7005]; signed main(){ int n,m; string a,b; cin>>a>>b; n = a.size(),m = b.size(); a = ' ' + a; b = ' ' + b; for (int i = 1;i <= n;i++){ for (int j = 1;j <= m;j++){ dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]); if (a[i] == b[j]){ dp[i][j] = max(dp[i][j],dp[i - 1][j - 1] + 1); } } } cout<<dp[n][m]; return 0; }