$$\color{red}{算法}\color{blue}{基础课}\color{purple}{笔记and题解}\color{green}{汇总}$$
有没有一种可能,本题和 这题 完全一样???
#include <bits/stdc++.h>
using namespace std;
const int N = 1015, M = 15;
int n, m;
char a[N][M], b[M];
int f[M][M];
int solve(char a[N], char b[N]) {
int n = strlen(a + 1), m = strlen(b + 1);
memset(f, 0x3f3f3f3f, sizeof f);
f[0][0] = 0;
for (int i = 1; i <= n; i++) f[i][0] = i;
for (int i = 1; i <= m; i++) f[0][i] = i;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
if (a[i] == b[j]) f[i][j] = min(f[i][j], f[i - 1][j - 1]); //直接匹配
else f[i][j] = f[i - 1][j - 1] + 1; //替换其一
f[i][j] = min({f[i][j], f[i - 1][j] + 1, f[i][j - 1] + 1}); //插入删除
}
return f[n][m];
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf(" %s", a[i] + 1);
while (m--) {
int d = 0; scanf(" %s %d", b + 1, &d);
int ans = 0;
for (int i = 1; i <= n; i++)
if (solve(a[i], b) <= d) ans++;
printf("%d\n", ans);
}
return 0;
}