902. 最短编辑距离
作者:互联网
#include<iostream>
using namespace std;
const int N = 1010;
char a[N], b[N];
int n, m;
int f[N][N];
int main(){
scanf("%d%s%d%s", &n, a + 1, &m, b + 1);
for(int i = 0; i <= m; i ++) f[0][i] = i;
for(int i = 0; i <= n; i ++) f[i][0] = i;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++){
f[i][j] = min(f[i - 1][j], f[i][j - 1]) + 1;
f[i][j] = min(f[i][j], f[i - 1][j - 1] + (a[i] != b[j]));
}
cout << f[n][m];
}
标签:902,std,const,int,d%,最短,编辑,main 来源: https://www.cnblogs.com/tomori/p/13685894.html