当前位置:网站首页>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;
}
边栏推荐
- Serial of H3CNE experiment column - spanning tree STP configuration experiment
- Leetcode notes of Google boss | necessary for school recruitment!
- 期货怎么开户安全些?哪些期货公司靠谱些?
- [play with Tencent cloud] & lt; trtc-room&gt; Applet component usage
- Experience and suggestions on cloud development database
- A set of very good H3C and Tianrongxin Internet cutover scheme templates, with word document download
- Enterprise security attack surface analysis tool
- [play with Tencent cloud] my operation strategy from domain name application to website filing in Tencent cloud
- A survey of training on graphs: taxonomy, methods, and Applications
- Tencent blue whale Zhiyun community version v6.0.3 was officially released together with the container management platform!
猜你喜欢

B. Terry sequence (thinking + greed) codeforces round 665 (Div. 2)

Ui- first lesson

Applet wxss
Advanced programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization

Some adventurer hybrid versions with potential safety hazards will be recalled

There are potential safety hazards Land Rover recalls some hybrid vehicles

Applet - use of template

C. K-th not divisible by n (Mathematics + thinking) codeforces round 640 (Div. 4)

A survey on dynamic neural networks for natural language processing, University of California

Ps\ai and other design software pondering notes
随机推荐
Detailed explanation of transpose convolution in pytorch
Serial of H3CNE experiment column - VLAN configuration experiment, access and trunk
Script design for automatic login and command return
【prometheus】1. Monitoring overview
Finite element simulation in design
Go path customized project path package dependency
A survey on dynamic neural networks for natural language processing, University of California
Tencent blue whale container management platform was officially released!
D. Solve the maze (thinking +bfs) codeforces round 648 (Div. 2)
企业安全攻击面分析工具
Interpretation of swin transformer source code
Week7 weekly report
Go deep into the implementation principle of go language defer
Serial of H3CNE experiment column - spanning tree STP configuration experiment
MySQL進階系列:鎖-InnoDB中鎖的情况
Introduction to koa (III) koa routing
What can Lu yuanjiu Jiao buy?
Automatically refresh CDN cache in real time based on cos log
Modern finite element analysis can easily achieve accurate results
Prometheus deployment