当前位置:网站首页>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 
边栏推荐
- Hash table acwing 841 String hash
- 区间DP AcWing 282. 石子合并
- There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
- Lekao.com: experience sharing of junior economists and previous candidates in customs clearance
- JDBC 预防sql注入问题与解决方法[PreparedStatement]
- Intel internal instructions - AVX and avx2 learning notes
- 堆 AcWing 838. 堆排序
- Embedded Software Engineer career planning
- Floyd AcWing 854. Floyd求最短路
- Drools terminates the execution of other rules after executing one rule
猜你喜欢

Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?

Counting class DP acwing 900 Integer partition
![2.7 binary tree, post order traversal - [FBI tree]](/img/6b/1ded3632cc69329d7b2762ce47fdbc.jpg)
2.7 binary tree, post order traversal - [FBI tree]

Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students

LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY

Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand

BOM DOM

Openssh remote enumeration username vulnerability (cve-2018-15473)

防抖 节流

JSON serialization and parsing
随机推荐
趣味 面试题
Simple use of drools decision table
Leetcode - Sword finger offer 37, 38
Redis bloom filter
In development, why do you find someone who is paid more than you but doesn't write any code?
What data types does redis have and their application scenarios
The second composition template of postgraduate entrance examination English / chart composition, English chart composition is enough
Some sudden program ideas (modular processing)
Bom Dom
Heap acwing 838 Heap sort
染色法判定二分图 AcWing 860. 染色法判定二分图
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
[ybtoj advanced training guidance] cross the river [BFS]
JDBC 预防sql注入问题与解决方法[PreparedStatement]
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
BOM DOM
spfa AcWing 852. spfa判断负环
Rust语言文档精简版(上)——cargo、输出、基础语法、数据类型、所有权、结构体、枚举和模式匹配
Enhance network security of kubernetes with cilium
Shutter encapsulated button