Mingyun's Scheme
InterviewTime limit1sMemory limit256 MB
Given N cards in order, compute the length of the longest strictly increasing subsequence.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Binary search
- Solved
- No attempts yet
Problem
Mingyun enjoys teasing Junmin. Today he prepares cards, each with one integer written on it, and shows them to Junmin in a fixed order. Junmin picks as many cards as he likes, keeping the order in which they were shown, and hands that sequence back to Mingyun. If the sequence Junmin hands back is not strictly increasing, Mingyun calls him a fool. Strictly increasing means every value is smaller than the value right after it. When the cards shown are , picking is safe, while or gets Junmin teased.
Junmin never slipped up, so Mingyun added one more condition. The sequence Junmin hands back must be strictly increasing and must also have as many elements as possible. When the cards are , picking or is safe, while or gets him teased.
Junmin decided to first work out how many elements such a sequence can have at most. For that number is . Write a program that computes it for him.
Input
The first line contains the number of cards () that Mingyun shows.
The second line contains the integers written on the cards, in the order they are shown, separated by spaces. Each integer is between and .
Output
Print on the first line the maximum number of elements in a sequence Junmin can hand back.