字串距离
来源:互联网 发布:朴在京 知乎 编辑:程序博客网 时间:2024/05/22 13:40
#include<iostream>
#include<string.h>
using namespace std;
int f[2001][2001];
char a[2001],b[2001];
int main()
{
cin>>a>>b;
int lena=strlen(a);
int lenb=strlen(b);
// cout<<lena<<' '<<lenb<<endl;
for(int i=0;i<=lena;i++)
{
for(int j=0;j<=lenb;j++)
{
if(i==0)
{
f[i][j]=j; continue;
}
if(j==0)
{
f[i][j]=i; continue;
}
if(a[i-1]==b[j-1])
{
f[i][j]=f[i-1][j-1];
continue;
}
f[i][j]=min(f[i-1][j-1],min(f[i-1][j],f[i][j-1]))+1;
}
}
cout<<f[lena][lenb];
return 0;
}
#include<string.h>
using namespace std;
int f[2001][2001];
char a[2001],b[2001];
int main()
{
cin>>a>>b;
int lena=strlen(a);
int lenb=strlen(b);
// cout<<lena<<' '<<lenb<<endl;
for(int i=0;i<=lena;i++)
{
for(int j=0;j<=lenb;j++)
{
if(i==0)
{
f[i][j]=j; continue;
}
if(j==0)
{
f[i][j]=i; continue;
}
if(a[i-1]==b[j-1])
{
f[i][j]=f[i-1][j-1];
continue;
}
f[i][j]=min(f[i-1][j-1],min(f[i-1][j],f[i][j-1]))+1;
}
}
cout<<f[lena][lenb];
return 0;
}
阅读全文
0 0
- 字串距离
- 字串距离
- 8.1 字串距离
- RQNOJ 字串距离
- bsoj1374字串距离
- 【cqbzoj 1227】字串距离
- 洛谷 P1279 字串距离
- 洛谷 P1279 字串距离
- 洛谷1279 字串距离
- rqnoj514 字串距离
- 洛谷 1279 字串距离
- 洛谷 P1279 字串距离
- P1279字串距离
- 字串距离(字符串dp)
- 【八中】字串距离
- 【20101106】动态规划训练:字串距离
- 【cqbzoj】:1227 字串距离 DP c++
- 2016东莞市特长生考试 字串距离(dp)
- 正则表达式
- 向量角度来重新审视一些数学概念
- cross-env简介
- LMCF文章阅读
- 杂记
- 字串距离
- bzoj3156 防御准备(斜率)
- LeetCode Algorithm #13 Roman to Integer
- Python BP神经网络解决非线性二分类问题
- CSS Hack技术介绍及常用的Hack技巧集锦
- 阿里巴巴Dubbo实现的源码分析
- 国王游戏(50)
- 一个登录的MVP例子
- Attempt to configure data store failed. Extended error message: Failed to configure tile cach