提交时间:2023-12-16 10:15:59

运行 ID: 116309

#include<bits/stdc++.h> using namespace std; int dp[5005][5005]; string a,b; int main(){ cin>>a>>b; int 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] == n?"true":"false"); return 0; }