题解
2025-03-28 21:46:10
发布于:江苏
1阅读
0回复
0点赞
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
char a[2005],b[2005];
int n,m,dp[2005][2005];
int main(){
cin>>a>>b;
n=strlen(a);
m=strlen(b);
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
if(i==0)
{
dp[0][j]=j;
}
else if(j==0)
{
dp[i][0]=i;
}
else if(a[i-1]==b[j-1])
{
dp[i][j]=dp[i-1][j-1];
}
else
{
dp[i][j]=min(min(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1])+1;
}
}
}
cout<<dp[n][m];
}
这里空空如也
有帮助,赞一个