int LCS(char *a,char *b) { if(a==NULL || b==NULL) return 0; int len_a = strlen(a); int len_b = strlen(b); int f[M][N]; for(int i=1;i<M;i++) f[i][0] = 0; f[0][0] = 0; int i,j; for(i=1;i<=len_a;i++) { for(j = 1;j<=len_b;j++) { if(a[i] == b[j]) { f[i][j] = f[i-1][j-1] + 1; } else f[i][j] = (f[i][j-1] > f[i-1][j] ? f[i][j-1]:f[i-1][j]); } } return f[i-1][j-1]; }