当前位置:网站首页>Linear DP acwing 902 Shortest editing distance
Linear DP acwing 902 Shortest editing distance
2022-07-02 12:43:00 【T_ Y_ F666】
linear DP AcWing 902. The shortest editing distance
Original link
AcWing 902. The shortest editing distance
Algorithm tags
Dynamic programming linear DP
Ideas
Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 1005, INF = 0x3f3f3f3f;
int n,m;
char A[N], B[N];
int f[N][N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
n=read();
scanf("%s", A+1);
m=read();
scanf("%s", B+1);
// if A It's empty B Yes i Characters Conduct i Add operations
rep(i, 0, m+1){
f[0][i]=i;
}
// if A Yes i Characters B It's empty Conduct i Delete operations
rep(i, 0, n+1){
f[i][0]=i;
}
rep(i, 1, n+1){
rep(j, 1, m+1){
f[i][j]=min(f[i-1][j], f[i][j-1])+1;
if(A[i]==B[j]){// No replacement operation required
f[i][j]=min(f[i][j], f[i-1][j-1]);
}else{
f[i][j]=min(f[i][j], f[i-1][j-1]+1);
}
}
}
printf("%lld", f[n][m]);
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support
边栏推荐
- Programmers can't find jobs after the age of 35? After reading this article, you may be able to find the answer
- PR 2021 quick start tutorial, learn about the and functions of the timeline panel
- 应用LNK306GN-TL 转换器、非隔离电源
- Docker compose configuration mysql, redis, mongodb
- When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device
- 线性DP AcWing 898. 数字三角形
- arcgis js 4. Add pictures to x map
- The second composition template of postgraduate entrance examination English / chart composition, English chart composition is enough
- Drools executes string rules or executes a rule file
- NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
猜你喜欢
区间DP AcWing 282. 石子合并
模块化 CommonJS ES Module
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
spfa AcWing 851. spfa求最短路
堆 AcWing 839. 模拟堆
js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately
Hash table acwing 840 Simulated hash table
Lekao: 22 year first-class fire engineer "technical practice" knowledge points
随机推荐
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
分布式机器学习框架与高维实时推荐系统
How to write a pleasing English mathematical paper
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
计数类DP AcWing 900. 整数划分
. Net, C # basic knowledge
3 A VTT端接 稳压器 NCP51200MNTXG资料
Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
js1day(输入输出语法,数据类型,数据类型转换,var和let区别)
JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
Lekao: 22 year first-class fire engineer "technical practice" knowledge points
The second composition template of postgraduate entrance examination English / chart composition, English chart composition is enough
Shuttle encapsulated AppBar
[ybtoj advanced training guidance] judgment overflow [error]
arcgis js 4. Add pictures to x map
通过反射执行任意类的任意方法
Lekao.com: experience sharing of junior economists and previous candidates in customs clearance
IPhone 6 plus is listed in Apple's "retro products" list
Simple understanding of ThreadLocal