当前位置:网站首页>Minimum editing distance (linear DP writing method)
Minimum editing distance (linear DP writing method)
2022-06-27 12:03:00 【Wu Yu 4】
Topic linking :902. The shortest editing distance - AcWing Question bank
Topic :
Ideas :
Code :
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1010;
ll n,m;
char a[N],b[N];
int f[N][N];
int main()
{
cin>>n;
cin>>a+1;
cin>>m;
cin>>b+1;
// Boundary treatment f[n][0] The required step is to delete n Step a Some elements
// Empathy f[0][m] The required step is to delete m Step b Some elements
for(int i=0;i<=n;i++) f[i][0]=i;
for(int i=0;i<=m;i++) f[0][i]=i;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
f[i][j]=min(f[i-1][j]+1,f[i][j-1]+1);// Compare the added and deleted operands to get the smaller value
// Here is the replacement operation , Judge whether it is the same ;
if(a[i]==b[j]) f[i][j]=min(f[i][j],f[i-1][j-1]);// In the same way, this does not require operands +1( There is no need to replace )
// Different operands need to be replaced 1
else f[i][j]=min(f[i][j],f[i-1][j-1]+1);
}
}
cout<<f[n][m]<<endl;
return 0;
}
边栏推荐
- Nvme2.0 protocol - new features
- Go Web 编程入门:验证器
- Challenges of machine learning system in production
- [tcapulusdb knowledge base] Introduction to tcapulusdb general documents
- The R language uses the follow up The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The labels parameter adds label information t
- Popular science of device review: popular science of innovative medical device series - sternum plate products
- Take stock of some easy-to-use and niche markdown editors
- FileOutputStream
- I.MX6ULL启动方式
- [tcapulusdb knowledge base] tcapulusdb doc acceptance - transaction execution introduction
猜你喜欢
nifi从入门到实战(保姆级教程)——身份认证
alibaba jarslink
从零开始搭建物联网系统
Redis distributed lock 15 ask, what have you mastered?
QStyle类用法总结(二)
如何修改 node_modules 里的文件
C/s architecture
Heap heap sort TOPK
Youboxun attended the openharmony technology day to create a new generation of secure payment terminals
MapReduce实战小案例(自定义排序、二次排序、分组、分区)
随机推荐
Youboxun attended the openharmony technology day to create a new generation of secure payment terminals
Online bidding of Oracle project management system
C语言0长度数组的妙用
Peak store app imitation station development play mode explanation source code sharing
This privatized deployed enterprise knowledge base makes telecommuting a zero distance
深入理解 happens-before 原则
QStyle类用法总结(二)
C # WPF realizes undo redo function
$15.8 billion! 2021 the world's top15 most profitable hedge fund giant
master公式
The R language uses the follow up The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The labels parameter adds label information t
namespace ‘rlang’ 0.2.0 is being loaded, but &gt;= 0.3.0 is required
Write it down once Net analysis of a property management background service stuck
C/s architecture
Summary of qstype class usage (II)
R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用step函数基于AIC指标实现逐步回归筛选最佳模型、解读分析模型
[tcapulusdb knowledge base] tcapulusdb doc acceptance - create business introduction
Interview shock 60: what will cause MySQL index invalidation?
Unity Shader学习(一)认识unity shader基本结构
Hands on API development