提交时间:2023-12-16 08:59:59

运行 ID: 116180

#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]); } } } cout << s1.size() + s2.size() - dp[s1.size()][s2.size()] * 2; return 0; }