当前位置:网站首页>Linear DP acwing 899 Edit distance
Linear DP acwing 899 Edit distance
2022-07-02 12:43:00 【T_ Y_ F666】
linear DP AcWing 899. Edit distance
Original link
Algorithm tags
Dynamic programming linear DP
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 s[N][N], a[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);
}
int dis(char a[], char b[]){
rep(i, 0, strlen(a+1)+1){
f[i][0]=i;
}
rep(i, 0, strlen(b+1)+1){
f[0][i]=i;
}
rep(i, 1, strlen(a+1)+1){
rep(j, 1, strlen(b+1)+1){
f[i][j]=min(f[i-1][j]+1, f[i][j-1]+1);
f[i][j]=min(f[i][j], f[i-1][j-1]+(a[i]!=b[j]));
}
}
return f[strlen(a+1)][strlen(b+1)];
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
n=read(),m=read();
rep(i, 0, n){
scanf("%s", s[i]+1);
}
while(m--){
int ans=0;
scanf("%s", a+1);
int b=read();
rep(i, 0, n){
if(dis(s[i], a)<=b){
ans++;
}
}
printf("%lld\n", ans);
}
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- 绕过ObRegisterCallbacks需要驱动签名方法
- std::vector批量导入快速去重方法
- spfa AcWing 852. spfa判断负环
- VLAN experiment
- The second composition template of postgraduate entrance examination English / chart composition, English chart composition is enough
- Sweetheart leader: Wang Xinling
- Calculate the maximum path sum of binary tree
- spfa AcWing 851. spfa求最短路
- Mongodb redis differences
- 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
猜你喜欢

Rust search server, rust quick service finding tutorial

spfa AcWing 852. SPFA judgement negative ring

js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)

防抖 节流

The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph
![[ybtoj advanced training guidance] cross the river [BFS]](/img/4e/83f14452ea6410768cdd01e725af2e.jpg)
[ybtoj advanced training guidance] cross the river [BFS]

传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE

浏览器存储方案

Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))

哈希表 AcWing 841. 字符串哈希
随机推荐
一些突然迸发出的程序思想(模块化处理)
Js10day (API phased completion, regular expression introduction, custom attributes, filtering sensitive word cases, registration module verification cases)
Browser node event loop
哈希表 AcWing 840. 模拟散列表
AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning
Record the range of data that MySQL update will lock
In development, why do you find someone who is paid more than you but doesn't write any code?
Simple use of drools decision table
Lekao: 22 year first-class fire engineer "technical practice" knowledge points
js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
Oracle从入门到精通(第4版)
Introduction to CPU instruction set
spfa AcWing 852. spfa判断负环
线性DP AcWing 898. 数字三角形
Async/await asynchronous function
spfa AcWing 852. SPFA judgement negative ring
Anti shake throttle
Redis introduction, scenario and data type
What data types does redis have and their application scenarios
AI mid stage technology research