PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000206. Độ dài dãy con tăng dài nhất (Longest Increasing Subsequence)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Độ dài dãy con tăng dài nhất (Longest Increasing Subsequence)
Longest Increasing Subsequence
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An integer sequence is given. A subsequence selects positions without requiring them to be consecutive. It is strictly increasing when . Find the maximum length of such a subsequence.
Input
The first line contains the sequence length . The second line contains integers in their original order.
Output
Print one integer: the maximum length.
Subtasks
- Subtask 1 (20 points): ; ().
- Subtask 2 (30 points): ; ().
- Subtask 3 (50 points): ; ().
Examples
Input
8
10 9 2 5 3 7 101 18
Output
4
Explanation
There are eight numbers. Positions 3, 5, 6 and 8 give , of length 4. The maximum lengths ending at the eight positions are . For instance, 7 can follow 2 and 3, and 18 can follow 7 but not 101. No position ends a longer subsequence.