当前位置:网站首页>线性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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 寻找二叉树中任意两个数的公共祖先
- Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime
- WSL 2 will not be installed yet? It's enough to read this article
- BOM DOM
- What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT
- Addition, deletion, modification and query of MySQL table (Advanced)
- kubeadm join时出现错误:[ERROR Port-10250]: Port 10250 is in use [ERROR FileAvailable--etc-kubernetes-pki
- AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning
- Sparkcontext: error initializing sparkcontext solution
- Intel internal instructions - AVX and avx2 learning notes
猜你喜欢

AI mid stage technology research

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

(C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?

kubenetes中port、targetPort、nodePort、containerPort的区别与联系

AI中台技术调研

drools决策表的简单使用

Simple use of drools decision table

Performance tuning project case

Sort---

BOM DOM
随机推荐
CDA数据分析——AARRR增长模型的介绍、使用
Distributed machine learning framework and high-dimensional real-time recommendation system
Docker-compose配置Mysql,Redis,MongoDB
Map和Set
LeetCode—<动态规划专项>剑指 Offer 19、49、60
Leetcode922 sort array by parity II
Leetcode - Sword finger offer 59 - I, 59 - II
2.7 binary tree, post order traversal - [FBI tree]
[C language] convert decimal numbers to binary numbers
H5 to app
倍增 LCA(最近公共祖先)
drools中then部分的写法
Leetcode922 按奇偶排序数组 II
Those logs in MySQL
Leetcode topic [array] -540- single element in an ordered array
Experiment of connecting mobile phone hotspot based on Arduino and esp8266 (successful)
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
lombok常用注解
FastDateFormat为什么线程安全
Multiply LCA (nearest common ancestor)