2022-02-07 02:55:47 +00:00
|
|
|
#include <iostream>
|
2022-06-01 01:45:41 +00:00
|
|
|
#include <algorithm>
|
2021-11-17 07:02:13 +00:00
|
|
|
|
2022-02-07 02:55:47 +00:00
|
|
|
using std::cin;
|
|
|
|
using std::cout;
|
|
|
|
#define endl '\n'
|
2021-11-17 07:02:13 +00:00
|
|
|
|
2022-02-07 02:55:47 +00:00
|
|
|
const int N = 1005;
|
|
|
|
|
|
|
|
int n, m, f[N][N];
|
|
|
|
char a[N], b[N];
|
2021-11-17 07:02:13 +00:00
|
|
|
|
|
|
|
int main() {
|
2022-02-07 02:55:47 +00:00
|
|
|
cin >> n >> a + 1 >> m >> b + 1;
|
|
|
|
for (int i = 1; i <= n; i++) {
|
2021-11-17 07:02:13 +00:00
|
|
|
f[i][0] = i;
|
|
|
|
}
|
2022-02-07 02:55:47 +00:00
|
|
|
for (int i = 1; i <= m; i++) {
|
2021-11-17 07:02:13 +00:00
|
|
|
f[0][i] = i;
|
|
|
|
}
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
for (int j = 1; j <= m; j++) {
|
2022-02-07 02:55:47 +00:00
|
|
|
f[i][j] = std::min({f[i - 1][j] + 1, f[i][j - 1] + 1, f[i - 1][j - 1] + (a[i] != b[j])});
|
2021-11-17 07:02:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cout << f[n][m] << endl;
|
|
|
|
return 0;
|
|
|
|
}
|