提交时间:2023-11-25 17:06:02

运行 ID: 112343

#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; }