当前位置:网站首页>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 
边栏推荐
猜你喜欢

Record the range of data that MySQL update will lock

Direct control PTZ PTZ PTZ PTZ camera debugging (c)

Drools dynamically add, modify, and delete rules

模块化 CommonJS ES Module

Hash table acwing 841 String hash

Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)

Floyd AcWing 854. Floyd finds the shortest path

Embedded Software Engineer career planning
![[ybtoj advanced training guide] similar string [string] [simulation]](/img/eb/acfefc7f85018fe9365d13502e2b0a.jpg)
[ybtoj advanced training guide] similar string [string] [simulation]

Linear DP acwing 896 Longest ascending subsequence II
随机推荐
Async/await asynchronous function
FBX import under ue4/ue5 runtime
[I'm a mound pytorch tutorial] learning notes
std::vector批量导入快速去重方法
JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
[ybtoj advanced training guide] similar string [string] [simulation]
2.7 binary tree, post order traversal - [FBI tree]
Sweetheart leader: Wang Xinling
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
Openssh remote enumeration username vulnerability (cve-2018-15473)
Rust search server, rust quick service finding tutorial
Leetcode - Sword finger offer 37, 38
架构师必须了解的 5 种最佳软件架构模式
JSON serialization and parsing
接口测试面试题目,你都会了吗?
Leetcode - Sword finger offer 59 - I, 59 - II
JDBC prevent SQL injection problems and solutions [preparedstatement]
Visual studio efficient and practical extension tools and plug-ins
About wechat enterprise payment to change x509certificate2 read certificate information, publish to the server can not access the solution
浏览器node事件循环