当前位置:网站首页>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 
边栏推荐
- Use sqoop to export ads layer data to MySQL
- Intel internal instructions - AVX and avx2 learning notes
- The second composition template of postgraduate entrance examination English / chart composition, English chart composition is enough
- Oracle从入门到精通(第4版)
- Is the neural network (pinn) with embedded physical knowledge a pit?
- JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
- Linear DP acwing 895 Longest ascending subsequence
- js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
- Redis sentinel mechanism and configuration
- What data types does redis have and their application scenarios
猜你喜欢

Linear DP acwing 896 Longest ascending subsequence II

Lekao: 22 year first-class fire engineer "technical practice" knowledge points

趣味 面试题

深拷贝 事件总线

Linear DP acwing 898 Number triangle

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

spfa AcWing 852. SPFA judgement negative ring

JSON serialization and parsing

Lekao.com: experience sharing of junior economists and previous candidates in customs clearance

Find the common ancestor of any two numbers in a binary tree
随机推荐
染色法判定二分图 AcWing 860. 染色法判定二分图
Lekao.com: experience sharing of junior economists and previous candidates in customs clearance
What data types does redis have and their application scenarios
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
浏览器node事件循环
1380. Lucky numbers in the matrix [two-dimensional array, matrix]
Introduction to CPU instruction set
High performance erasure code coding
Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold
BOM DOM
[ybtoj advanced training guidance] judgment overflow [error]
2.6 using recursion and stack - [tower of Hanoi problem]
[I'm a mound pytorch tutorial] learning notes
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
通过反射执行任意类的任意方法
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
Docker compose configuration mysql, redis, mongodb
模块化 CommonJS ES Module
The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night