#T138. 求最长不下降序列
求最长不下降序列
Description
Given a sequence of (where ) distinct integers, denoted as , with for ,
if there exist indices such that , then this is called a non-decreasing subsequence of length .
The task is to find the longest non-decreasing subsequence after the original sequence is given.
For example, consider the sequence:
13, 7, 9, 16, 38, 24, 37, 18, 44, 19, 21, 22, 63, 15.
In this case, 13, 16, 18, 19, 21, 22, 63 is a non-decreasing subsequence of length 7,
while 7, 9, 16, 18, 19, 21, 22, 63 forms a longer non-decreasing subsequence of length 8.
Input Format
- The first line contains an integer .
- The second line contains space-separated integers.
Output Format
- The first line should output the maximum length
max(as shown in the sample). - The second line should output one of the longest non-decreasing subsequences. The answer may not be unique; any valid sequence is acceptable. Special judging will be applied for this problem.
Sample Input
14
13 7 9 16 38 24 37 18 44 19 21 22 63 15
Sample Output
max=8
7 9 16 18 19 21 22 63
14
13 7 9 16 38 24 37 18 44 19 21 22 63 15
max=8