#T247. 最长公共子上升序列
最长公共子上升序列
Description
Given two integer sequences, write a program to find their longest increasing common subsequence.
A sequence of length is called an increasing subsequence of a sequence of length when the following conditions are satisfied:
There exist indices such that for all , , and for all , .
Input Format
Each sequence is represented by two lines. The first line contains the length (), and the second line contains the integers () of the sequence.
Output Format
On the first line, output the length of the longest increasing common subsequence of the two sequences. On the second line, output the subsequence. If there are multiple valid subsequences, any one may be printed.
5
1 4 2 5 -12
4
-12 1 2 4
2
1 4
Hint
Classic algorithm Baidu search, deeply comprehend.