原文链接:https://www.luogu.com.cn/problem/P2758
AC代码:
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
int dp[2005][2005];
int main(){
int i,j;
string s0,s1;
cin>>s0>>s1;
for(i=1;i<2005;i++){
dp[0][i]=i;
dp[i][0]=i;
for(j=1;j<2005;j++){
dp[i][j]=2005;
}
}
dp[0][0]=0;
for(i=1;i<=s0.length();i++){
for(j=1;j<=s1.length();j++){
if(s0[i-1]==s1[j-1]){
dp[i][j]=min(dp[i][j],dp[i-1][j-1]);
}
else{
dp[i][j]=min(dp[i][j],min(dp[i-1][j],min(dp[i][j-1],dp[i-1][j-1])))+1;
}
}
}
cout<<dp[s0.length()][s1.length()]<<endl;
return 0;
}