#graph604. 最长递增子序列
最长递增子序列
Longest Increasing Subsequence
Problem Source
Network Flow 24 Problems
Problem Description
Given a sequence of positive integers (an increasing subsequence below means non-strictly increasing):
- Compute the length of its longest increasing subsequence.
- Compute the maximum number of increasing subsequences of length that can be taken from the given sequence (no element may be reused).
- If and are allowed to be used multiple times in the taken subsequences, compute the maximum number of increasing subsequences of length that can be taken.
Input Format
The first line contains one positive integer , the length of the given sequence. The next line contains positive integers .
Output Format
Three lines, each with one integer, giving the answer to the corresponding question above.
Sample Input
4
3 6 2 5
Sample Output
2
2
3
Constraints
.
Hint
- First compute the longest increasing subsequence length with DP. Questions 2 and 3 are classic maximum-flow problems: build a layered network where each element is split into an in-node and an out-node (capacity 1, or infinite for and in question 3), and connect elements that can extend an increasing subsequence.