最短编辑距离 – 算法板子

#include<bits/stdc++.h> using namespace std; int n, m; const int N = 1010; string s1, s2; int dp[N][N]; int main() {     cin >> n >> s1;     cin >> m >> s2;     memset(dp, 0x3f, sizeof dp);     dp[0][0] = 0;     for (int i = 1; i <= n; ++i) {         dp[i][0] = i;     }     for (int i = 1; i <= m; ++i) {         dp[0][i] = i;     }     for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) {             if (s1[i - 1] == s2[j - 1]) {                 dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);             }             dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1);             dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);             dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);         }     }     cout << dp[n][m] << endl;     return 0; }

最短编辑距离 – 算法板子leetcode刷题题解部分资料来自网络,侵权毕设源码联系删除

区块链毕设网(www.qklbishe.com)全网最靠谱的原创区块链毕设代做网站
部分资料来自网络,侵权联系删除!
资源收费仅为搬运整理打赏费用,用户自愿支付 !
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台 » 最短编辑距离 – 算法板子leetcode刷题题解