思路
其实就是求编辑最短路的问题,只不过多了几个字符串而已
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
const int N=1005;
int f[15][15];
char str[N][15];
int main(){
int n,m;
cin >> n >> m;
for (int i = 0; i < n; i ++ ) scanf("%s", str[i] + 1);
while(m--){
char a[15];int limit;
scanf("%s%d",a+ 1,&limit);
int ans=0;
for(int k=0;k<n;k++){
memset(f,0,sizeof(f));
int len2=strlen(a+1);
int len1=strlen(str[k]+1);
for(int i=0;i<=len1;i++)f[i][0]=i;
for(int i=0;i<=len2;i++)f[0][i]=i;
for(int i=1;i<=len1;i++){
for(int j=1;j<=len2;j++){
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] + (str[k][i] != a[j]));
}
}
if(f[len1][len2]<=limit)
ans++;
}
cout << ans << "\n";
}
}