提交时间:2023-11-28 13:26:07

运行 ID: 112730

#include<iostream> #include<string> #include<algorithm> using namespace std; string S,T; const int MAXN = 5005; int f[MAXN][MAXN]; int main(){ cin>>S; cin>>T; int ls = S.length(),lt = T.length(),i,j; for(i = 1;i <= ls;i++){ for(j = 1;i <= lt;j++){ f[i][j] = max(f[i - 1][j],f[i][j - 1]); if(S[i - 1] == T[j - 1]){ f[i][j] = max(f[i][j],f[i - 1][j - 1] + 1); } } } cout<<f[ls][lt]<<endl; return 0; }