当前位置:网站首页>Edit distance (linear dp+ violence matching)
Edit distance (linear dp+ violence matching)
2022-06-24 16:38:00 【MangataTS】
Topic link
https://www.acwing.com/problem/content/901/
Ideas
In fact, the idea of this question is the same as that of the previous question , It's just that we need to do something about every inquiry n Secondary matching judgment , If the current number of operations is less than k That means our string is legal , The minimum number of times it takes to match two strings , We can do the last one : Minimum edit distance
Code
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+10;
int n,m;
char a[N][15],b[20];
int f[20][20],la[N];
int main()
{
cin>>n>>m;
for(int i = 1;i <= n; ++i) {
cin>>(a[i]+1);
la[i]=strlen(a[i]+1);
}
while(m--){
int cnt;
cin>>(b+1)>>cnt;
int lb = strlen(b+1);
int ans = 0;
for(int i = 1;i <= n; ++i) {
// initialization
for(int j = 0;j <= la[i]; ++j) f[j][0] = j;
for(int j = 0;j <= lb; ++j) f[0][j] = j;
for(int j = 1;j <= la[i]; ++j)
for(int k = 1;k <= lb; ++k){
f[j][k] = min(f[j-1][k]+1,f[j][k-1]+1);
if(a[i][j] == b[k]) f[j][k] = min(f[j-1][k-1],f[j][k]);
else f[j][k] = min(f[j-1][k-1] + 1,f[j][k]);
}
if(f[la[i]][lb] <= cnt) ans++;
}
cout<<ans<<endl;
}
return 0;
}
边栏推荐
- Kubernetes characteristic research: sidecar containers
- 6 things all engineers should know before FEA
- What is cloud development? Why cloud development? Talk about our story
- What does the router pin mean?
- C. K-th not divisible by n (Mathematics + thinking) codeforces round 640 (Div. 4)
- Detailed explanation of transpose convolution in pytorch
- Transpose convolution learning notes
- Summer Challenge harmonyos - to do list with date effect
- What is a reptile
- Percona Toolkit series - Pt deadlock logger
猜你喜欢

Some adventurer hybrid versions with potential safety hazards will be recalled

A survey on dynamic neural networks for natural language processing, University of California
MySQL Advanced Series: Locks - Locks in InnoDB
MySQL進階系列:鎖-InnoDB中鎖的情况

Applet - use of template

Cognition and difference of service number, subscription number, applet and enterprise number (enterprise wechat)
MySQL Advanced Series: locks - locks in InnoDB

C. Three displays codeforces round 485 (Div. 2)

Problems encountered in the work of product manager

C. K-th not divisible by n (Mathematics + thinking) codeforces round 640 (Div. 4)
随机推荐
Goby+AWVS 实现攻击面检测
Detailed explanation of transpose convolution in pytorch
Join in ABAP CDs
API documents are simple and beautiful. It only needs three steps to open
Private domain defense in the cotton Era
Druid architecture and Implementation
6 things all engineers should know before FEA
Load MySQL table data consumption quick installation configuration through kafka/flink
Ui- first lesson
What is cloud development? Why cloud development? Talk about our story
Coding's first closed door meeting on financial technology exchange was successfully held
Annual contribution! Tencent cloud middleware product upgrade conference is in hot registration!
Regular expression learning artifact!
[the activity is over, and the list of winners is announced] in March, techo youth university open class demo practice
[go] runtime package for concurrent programming and its common methods
Introduction to koa (III) koa routing
Introduction to website development for zero foundation Xiaobai
Some adventurer hybrid versions with potential safety hazards will be recalled
Cloud + community [play with Tencent cloud] video solicitation activity winners announced
AI structured intelligent security video monitoring technology, supporting the protective umbrella of the reserve / wild animals