当前位置:网站首页>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
边栏推荐
- Leetcode - Sword finger offer 51 Reverse pairs in an array
- NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
- 绕过ObRegisterCallbacks需要驱动签名方法
- Mongodb redis differences
- 3 A VTT端接 稳压器 NCP51200MNTXG资料
- 传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE
- JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
- Linear DP acwing 898 Number triangle
- . Net, C # basic knowledge
- 哈希表 AcWing 840. 模拟散列表
猜你喜欢
8 examples of using date commands
Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime
Distributed machine learning framework and high-dimensional real-time recommendation system
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
浏览器node事件循环
1380. Lucky numbers in the matrix [two-dimensional array, matrix]
Browser node event loop
bellman-ford AcWing 853. 有边数限制的最短路
Lekao.com: experience sharing of junior economists and previous candidates in customs clearance
js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
随机推荐
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
BOM DOM
Rust search server, rust quick service finding tutorial
Linear DP acwing 896 Longest ascending subsequence II
Interview questions for software testing - a collection of interview questions for large factories in 2022
Shuttle encapsulated AppBar
Docker compose configuration mysql, redis, mongodb
[ybtoj advanced training guide] similar string [string] [simulation]
Linear DP acwing 902 Shortest editing distance
Execute any method of any class through reflection
浏览器存储方案
基于STM32的OLED 屏幕驱动
High performance erasure code coding
AI mid stage technology research
模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
Leetcode - Sword finger offer 59 - I, 59 - II
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
Calculate the maximum path sum of binary tree
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
Sweetheart leader: Wang Xinling