提交时间:2023-12-16 10:09:22

运行 ID: 116301

#include<bits/stdc++.h> #define int long long using namespace std; int dp[2005][2005]; signed main(){ int n,m; string a,b; cin>>a>>b; n = a.size(); m = b.size(); for (int i = 0;i <= n;i++){ for (int j = 0;j <= m;j++){ if (i == 0){ dp[i][j] = j; continue; } else if (j == 0){ dp[i][j] = i; continue; } dp[i][j] = min(min(dp[i - 1][j],dp[i][j - 1]),dp[i - 1][j - 1]) + 1; if (a[i - 1] == b[j - 1]){ dp[i][j] = dp[i - 1][j - 1]; } } } cout<<dp[n][m]<<endl; return 0; }