待续:待研究,比较最长子序列和最长子串,研究后缀数组和后缀树
LCS实现代码:
#includeusing namespace std;int c[8][7],b[8][7];void lcs_length(char *X,char *Y){ int m = strlen(X); int n = strlen(Y); for ( int i = 0; i <=m; i++)c[i][0] = 0; for(int j = 0; j <=n; j++)c[0][j] = 0; for(int i = 1; i <=m; i++) for (int j = 1; j <=n; j++) { int s_i = i - 1; int s_j = j - 1; if (X[s_i] == Y[s_j]) { c[i][j] = c[i-1][j-1]+1; b[i][j] = 2; } else { if (c[i-1][j] >= c[i][j-1]) { c[i][j] = c[i-1][j]; b[i][j] = 3; } else { c[i][j] = c[i][j-1]; b[i][j] = 1; } } }}void print_lcs(char *X,int i,int j){ if (i == 0 || j == 0)return; if (b[i][j] == 2) { print_lcs(X,i-1,j-1); int s_i = i - 1; cout<