2 wa 求助
查看原帖
2 wa 求助
482660
konyakest楼主2022/4/9 19:02
// Problem: P2758 编辑距离
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P2758
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define F(i,j,k) for (signed i=signed(j);i<=signed(k);i++)
#define endl '\n'
//#define int long long
char a[2005],b[1005];
int f[2005][2005];
int lena,lenb;
main() { 
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>(a+1)>>(b+1);
	lena=strlen(a+1),lenb=strlen(b+1);
	F(i,0,lena){
		F(j,0,lenb){
			f[i][j]=max(i,j);
			if(a[i]==b[j]&&i>0&&j>0) f[i][j]=min(f[i][j],f[i-1][j-1]);
			if(i>0) f[i][j]=min(f[i][j],f[i-1][j]+1);
			if(j>0) f[i][j]=min(f[i][j],f[i][j-1]+1);
			if(i>0&&j>0) f[i][j]=min(f[i][j],f[i-1][j-1]+1);
		}
	}
	cout<<f[lena][lenb]<<endl;
	return 0; 
}
2022/4/9 19:02
加载中...