当前位置:网站首页>最短编辑距离(线性dp写法)
最短编辑距离(线性dp写法)
2022-06-27 11:33:00 【吴雨4】
题面:

思路:

代码:
#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;
//边界处理当f[n][0]时需要的步骤是删除n步a有的元素
//同理f[0][m]时需要的步骤是删除m步b有的元素
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);//比较增删的操作数取小值
//这里是替换的操作,判断是否相同;
if(a[i]==b[j]) f[i][j]=min(f[i][j],f[i-1][j-1]);//相同的话这不需要操作数+1(不需要替换)
//不同则需要加上替换的操作数1
else f[i][j]=min(f[i][j],f[i-1][j-1]+1);
}
}
cout<<f[n][m]<<endl;
return 0;
}
边栏推荐
- Summary of qstype class usage (II)
- Jerry's constant feeding of dogs will cause frequent switch interruptions leading to timer [chapter]
- 杰理之DAC输出方式设置【篇】
- StarCraft's Bug King ia retired for 2 years to engage in AI, and lamented that it was inferior
- Xuri 3sdb, installing the original ROS
- Research Report on the overall scale, major producers, major regions, products and application segments of swine vaccine in the global market in 2022
- R语言使用epiDisplay包的poisgof函数对泊松回归(Poisson Regression)执行拟合优度检验、检验是否存在过度离散问题(overdispersion)
- 【TcaplusDB知识库】TcaplusDB-tcapsvrmgr工具介绍(一)
- c/s 架构
- 巅峰小店APP仿站开发玩法模式讲解源码分享
猜你喜欢

【TcaplusDB知识库】TcaplusDB运维单据介绍

面试突击60:什么情况会导致 MySQL 索引失效?

Rxjs mergeMap 的使用场合

Peak store app imitation station development play mode explanation source code sharing

Excel中输入整数却总是显示小数,如何调整?
![[worthy of collection] centos7 installation MySQL complete operation command](/img/23/7c4b69e1abc3a3ceba9b79cebe1c9b.png)
[worthy of collection] centos7 installation MySQL complete operation command

0基础了解电商系统如何对接支付渠道

Prevent being rectified after 00? I. The company's recruitment requires that employees cannot sue the company

等等, 怎么使用 SetMemoryLimit?

器审科普:创新医疗器械系列科普——胸骨板产品
随机推荐
QStyle类用法总结(二)
Youboxun attended the openharmony technology day to create a new generation of secure payment terminals
Thinkphp6 interface limits user access frequency
Research Report on the overall scale, major producers, major regions, products and application segments of swine vaccine in the global market in 2022
Mqtt protocol stack principle and interaction flow chart
Qstype implementation of self drawing interface project practice (I)
Jerry's seamless looping [chapter]
杰理之一直喂狗会频繁开关中断导致定时器【篇】
建木持续集成平台v2.5.0发布
15+ urban road element segmentation application, this segmentation model is enough!
R language uses GLM function to build Poisson logarithm linear regression model, processes three-dimensional contingency table data to build saturation model, uses step function to realize stepwise re
干货!零售业智能化管理会遇到哪些问题?看懂这篇文章就够了
Unity Shader学习(一)认识unity shader基本结构
1. Mx6ull startup mode
FileOutputStream
In 2021, the global professional liability insurance revenue was about USD 44740million, and it is expected to reach USD 55980million in 2028. From 2022 to 2028, the CAGR was 3.5%
After Jerry's sleep, the regular wake-up system continues to run without resetting [chapter]
What is the TCP 3-time handshake process?
【TcaplusDB知识库】TcaplusDB运维单据介绍
星际争霸的虫王IA退役2年搞AI,自叹不如了