当前位置:网站首页>线性DP AcWing 899. 编辑距离
线性DP AcWing 899. 编辑距离
2022-07-02 09:43:00 【T_Y_F666】
线性DP AcWing 899. 编辑距离
原题链接
算法标签
动态规划 线性DP
代码
#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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 1380. Lucky numbers in the matrix [two-dimensional array, matrix]
- 堆(优先级队列)
- LeetCode—剑指 Offer 59 - I、59 - II
- Use sqoop to export ads layer data to MySQL
- Introduction to CPU instruction set
- Is the neural network (pinn) with embedded physical knowledge a pit?
- Anti shake throttle
- 趣味 面试题
- Shuttle encapsulated AppBar
- ThreadLocal的简单理解
猜你喜欢
"As a junior college student, I found out how difficult it is to counter attack after graduation."
mysql表的增删改查(进阶)
SparkContext: Error initializing SparkContext解决方法
kubenetes中port、targetPort、nodePort、containerPort的区别与联系
Heap (priority queue)
Openssh remote enumeration username vulnerability (cve-2018-15473)
Embedded Software Engineer career planning
防抖 节流
[ybtoj advanced training guide] similar string [string] [simulation]
Sweetheart leader: Wang Xinling
随机推荐
Leetcode - Sword finger offer 59 - I, 59 - II
Go学习笔记—多线程
Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime
BOM DOM
Anti shake throttle
[ybtoj advanced training guide] similar string [string] [simulation]
记录一下MySql update会锁定哪些范围的数据
ThreadLocal的简单理解
Input box assembly of the shutter package
The second composition template of postgraduate entrance examination English / chart composition, English chart composition is enough
drools决策表的简单使用
Sse/avx instruction set and API of SIMD
Jenkins user rights management
单指令多数据SIMD的SSE/AVX指令集和API
LeetCode—剑指 Offer 37、38
Go learning notes - go based interprocess communication
Sparkcontext: error initializing sparkcontext solution
中国交通标志检测数据集
drools中then部分的写法
CDA数据分析——AARRR增长模型的介绍、使用