提交时间:2023-12-16 09:45:00
运行 ID: 116245
#include <bits/stdc++.h> using namespace std; int xiaoJB(string s, string t) { int n = s.length(), m = t.length(); vector< vector<int> > dp(n + 1, vector<int>(m + 1, 0)); for (int i = 1; i <= n; i++) { dp[i][0] = i; } for (int j = 1; j <= m; j++) { dp[0][j] = j; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (s[i - 1] == t[j - 1]) { dp[i][j] = dp[i - 1][j - 1]; } else { dp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1; } } } return dp[n][m]; } int main(){ string x,y; cin>>x>>y; cout<<xiaoJB(x,y)<<endl; return 0; }