j组补充程序t2
  • 板块灌水区
  • 楼主nightwatch.ryan
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/9/16 21:48
  • 上次更新2023/11/2 19:57:45
查看原帖
j组补充程序t2
961351
nightwatch.ryan楼主2023/9/16 21:48
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int min(int x,int y,int z){
	return min(min(x,y),z);
}
int edit_dist_dp(std::string str1,std::string str2){
	int m=str1.length();
	int n=str2.length();
	std::vector< std::vector< int > >dp(m+1,std::vector< int >(n+1));
	for(int i=0;i<=m;i++){
		for(int j=0;j<=n;j++){
			if(i==0){
				dp[i][j]=j;
			}
			else if(j==0){
				dp[i][j]=i;
			}
			else if(str1[i-1]==str2[j-1]){
				dp[i][j]=dp[i-1][j-1];
			}
			else
				dp[i][j]=1+min(dp[i][j-1],dp[i-1][j],dp[i-1][j-1]);
		}
	}
	return dp[m][n];
}
int main(){
	string str1,str2;
	cin>>str1>>str2;
	cout<<edit_dist_dp(str1,str2);
}

AC记录:https://www.luogu.com.cn/record/124922470

2023/9/16 21:48
加载中...