Given two sequences s1
and s2
(of any type). Find their longest common subsequence(s) (LCS). For example, let s1 = {3, 6, 5, 7, 7, 1, 4, 8}
and s2 = {4, 45, 7, 7, 1, 9, 3, 6}
. Their LCS is {7, 7, 1}
of length 3
. Implement this function as a template that works on any class T
, and call your function template with int
. The I/O format is as follows.
len
then your program should only output the length of the LCS.seq
then your program should output all LCSs. If there are more than one, then your program should output them in lexicographic order.
14
343 5 3 434 1 2 3 4 5 6 7 8 9 10
13
9 2348 32 5 1 2 3 4 5 6 88 9934 0
len
6
14
343 5 3 434 1 2 3 4 5 6 7 8 9 10
13
9 2348 32 5 1 2 3 4 5 6 88 9934 0
str
1 2 3 4 5 6
10
18 3 1 4 7 7 5 3 9 6
11
8 78 5 3 9 2 9 1 4 7 10
str
1 4 7
5 3 9