com.dynamic; { [] seqA; [] seqB; [][] memory; [][]b; LongestCommonSubSequence([]seqA, []seqB){ .seqAseqA; .seqBseqB; memory [seqA.length][seqB.length]; ( i;iseqA.length;i){ ( j;jseqB.length;j){ memory[i][j]; } } b [seqA.length][seqB.length]; } lcsLength(){ innerLcsLength(seqA.length,seqB.length); } innerLcsLength( i, j){ (ij){ ; } (memory[i][j]){ memory[i][j]; } tmp; (ijseqA[i]seqB[j]){ tmp innerLcsLength(i,j); b[i][j]; } (innerLcsLength(i,j)innerLcsLength(i,j)){ tmp innerLcsLength(i,j); b[i][j]; }{ tmpinnerLcsLength(i,j); b[i][j]; } memory[i][j]tmp; tmp; } printLcs(){ innerPrintLcs(seqA.length,seqB.length); } innerPrintLcs( i, j){ (ij){ ; } (b[i][j]){ innerPrintLcs(i,j); System.out.print(seqA[i]); } (b[i][j]){ innerPrintLcs(i,j); }{ innerPrintLcs(i,j); } } main([] args) { []seqA []{,,,,,,}; [] seqB []{,,,,,}; LongestCommonSubSequence lcs LongestCommonSubSequence(seqA,seqB); System.out.println(lcs.lcsLength()); lcs.printLcs(); } }