提交时间:2023-12-16 09:07:50
运行 ID: 116201
#include<iostream> #include<string> using namespace std; const int N = 1e3 + 10; int n, dp[N][N]; string s1, s2; int main(){ cin >> s1 >> s2; for(int i = 1; i <= s1.size(); i++){ for(int j = 1; j <= s2.size(); j++){ if(s1[i-1] == s2[j-1]){ dp[i][j] = dp[i - 1][j - 1] + 1; } else{ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } } if(dp[s1.size()][s2.size()] == s1.size()) cout << "true"; else cout << "false"; return 0; }