当前位置:网站首页>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 
边栏推荐
- 2.6 using recursion and stack - [tower of Hanoi problem]
- Wechat official account payment prompt MCH_ ID parameter format error
- Js7day (event object, event flow, event capture and bubble, prevent event flow, event delegation, student information table cases)
- Distributed machine learning framework and high-dimensional real-time recommendation system
- JDBC 预防sql注入问题与解决方法[PreparedStatement]
- Calculate the maximum path sum of binary tree
- Mui WebView down refresh pull-up load implementation
- Linear DP acwing 895 Longest ascending subsequence
- Browser node event loop
- 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
猜你喜欢

Execute any method of any class through reflection

BOM DOM

Enhance network security of kubernetes with cilium

JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))

线性DP AcWing 897. 最长公共子序列

Record the range of data that MySQL update will lock

防抖 节流

JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)

堆 AcWing 838. 堆排序

spfa AcWing 852. spfa判断负环
随机推荐
百款拿来就能用的网页特效,不来看看吗?
JDBC prevent SQL injection problems and solutions [preparedstatement]
Redis avalanche, penetration, breakdown
Docker compose configuration mysql, redis, mongodb
Shuttle encapsulated AppBar
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
2.6 using recursion and stack - [tower of Hanoi problem]
This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry
Drools terminates the execution of other rules after executing one rule
async/await 异步函数
哈希表 AcWing 841. 字符串哈希
Simple use of drools decision table
spfa AcWing 851. SPFA finding the shortest path
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
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
线性DP AcWing 898. 数字三角形
Mui WebView down refresh pull-up load implementation
Execute any method of any class through reflection
Openssh remote enumeration username vulnerability (cve-2018-15473)
8 examples of using date commands