提交时间:2023-11-25 16:41:25
运行 ID: 112335
#include<bits/stdc++.h> using namespace std; int dp[5005][5005]; int 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 <= n;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); } } } printf("%d",dp[n][m]); return 0; }