42 int w,
int s,
int a,
int d)
45 int *row0 =
malloc(
sizeof(
int) * (len2 + 1));
46 int *row1 =
malloc(
sizeof(
int) * (len2 + 1));
47 int *row2 =
malloc(
sizeof(
int) * (len2 + 1));
50 for (j = 0; j <= len2; j++)
52 for (i = 0; i < len1; i++) {
55 row2[0] = (i + 1) * d;
56 for (j = 0; j < len2; j++) {
58 row2[j + 1] = row1[
j] + s * (string1[
i] != string2[
j]);
60 if (i > 0 && j > 0 && string1[i - 1] == string2[j] &&
61 string1[i] == string2[j - 1] &&
62 row2[j + 1] > row0[j - 1] + w)
63 row2[j + 1] = row0[j - 1] +
w;
65 if (row2[j + 1] > row1[j + 1] + d)
66 row2[j + 1] = row1[j + 1] +
d;
68 if (row2[j + 1] > row2[j] + a)
69 row2[j + 1] = row2[
j] +
a;