#CT00050. Dãy tăng (Longest Increasing Subsequence)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dãy tăng (Longest Increasing Subsequence)
Longest Increasing Subsequence
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer sequence of length , , a subsequence is obtained by selecting elements while preserving their order in the original sequence. It is strictly increasing if each subsequent element is greater than its predecessor.
Find the maximum possible length of a strictly increasing subsequence.
Input
The first line contains a positive integer .
The second line contains integers .
Output
Print one integer: the length of a longest strictly increasing subsequence.
Subtasks
.
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
8
3 1 2 1 8 5 6 7
Output
5
Explanation
Choose at position , at , at , at , and at . The resulting subsequence has length five, which is maximal.
Example 2
Input
5
5 4 3 2 1
Output
1
Explanation
The sequence is strictly decreasing. No pair of elements selected in original order can increase, so any single element forms a longest valid subsequence of length one.
Example 3
Input
6
1 2 2 3 3 4
Output
4
Explanation
Choose , one of the two s, one of the two s, and . This gives length four. Equal values cannot be consecutive in a strictly increasing subsequence, so length five or six is impossible.
Liên quan
Trong các cuộc thi sau: