// smc-simple.c
// << Algorithmique du texte >>
// Maxime Crochemore, Christophe Hancart et Thierry Lecroq
// Vuibert, 2001.
#include <stdio.h>
#include "chl.h"
#define S(i,j) s[((i) + 1)*(n + 1) + (j) +1]
int smcSimple(Mot x, Longueur m, Mot y, Longueur n) {
int i, j, *s;
s = (int *)malloc((m + 2)*(n + 2)*sizeof(int));
if (s == NULL) error("smcSimple");
for (i = -1; i <= m - 1; ++i) S(i, -1) = 0; // memset(s, 0, (m + 1)*sizeof(int));
for (j = 0; j <= n - 1; ++j) {
S(-1, j) = 0;
for (i = 0; i <= m - 1; ++i)
if (x[i] == y[j])
S(i, j) = S(i - 1, j - 1) + 1;
else
S(i, j) = MAX(S(i - 1, j), S(i, j - 1));
}
return(S(m - 1, n - 1));
}