当前位置:网站首页>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;
}
边栏推荐
- What does the router pin mean?
- 期货怎么开户安全些?哪些期货公司靠谱些?
- Customized Tile Map cut - based on Tencent map
- The mystery of redis data migration capacity
- AI video structured intelligent security platform easycvr realizes intelligent security monitoring scheme for procuratorate building
- [tke] modify the cluster corendns service address
- Clickhouse high performance column storage core principle
- Fastjson 漏洞利用技巧
- [security] graphical CSRF injection of Web Security (II)
- Heavy release! Tencent cloud ASW workflow, visual orchestration cloud service
猜你喜欢

Problems encountered in the work of product manager

A survey on model compression for natural language processing (NLP model compression overview)

There are potential safety hazards Land Rover recalls some hybrid vehicles

Applet - use of template

Ui- first lesson

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

Ps\ai and other design software pondering notes
MySQL進階系列:鎖-InnoDB中鎖的情况
MySQL Advanced Series: locks - locks in InnoDB
MySQL Advanced Series: Locks - Locks in InnoDB
随机推荐
Abnormal dockgeddon causes CPU 100%
Applet wxss
Introduction to koa (III) koa routing
Transpose convolution explanation
Object store signature generation
Pytorch transpose convolution
50 growers | closed door meeting of marketing circle of friends ス gathering Magic City thinking collision to help enterprise marketing growth
It may be a good idea to use simulation software in the cloud for simulation
Principle analysis of robot hardware in the loop system
Factory mode
How to open a futures account safely? Which futures companies are more reliable?
Embedded Software Engineer written interview guide arm system and architecture
【prometheus】1. Monitoring overview
Don't let [mana] destroy your code!
Handling of communication failure between kuberbetes pod
A troubleshooting of golang memory leak
Fastjson 漏洞利用技巧
Memo list: useful commands for ffmpeg command line tools
If only 2 people are recruited, can the enterprise do a good job in content risk control?
Is Shanjin futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?