51nod 1183 编辑距离(dp)

题目链接:51nod 1183 编辑距离

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
char a[N], b[N];
int dp[N][N];//dp[i][j]:a串的前i个字符转化成b串的前j个字符的最少操作数
int main(){
int i, j;
scanf("%s%s", a+, b+);
int alen = strlen(a+);
int blen = strlen(b+);
for(i = ; i <= alen; ++i)
dp[i][] = i;
for(j = ; j <= blen; ++j)
dp[][j] = j;
for(i = ; i <= alen; ++i)
for(j = ; j <= blen; ++j)
dp[i][j] = min(dp[i-][j-] + (a[i]!=b[j]), min(dp[i-][j]+, dp[i][j-]+));
printf("%d\n", dp[alen][blen]);
return ;
}
上一篇:Redhat/Ubuntu/Windows下安装Docker


下一篇:Eclipse出现the type java.lang.CharSequence can't be resolved.