PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000056. Lồng các phong bì (Russian Doll Envelopes)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Lồng các phong bì (Russian Doll Envelopes)
Russian Doll Envelopes
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
You have envelopes. An envelope fits inside another only when both its width and height are strictly smaller. Rotation is forbidden. Find the maximum number of envelopes in a nested chain.
Input
The first line contains , followed by pairs of envelope width and height .
Output
Print the maximum number of envelopes in a nested chain.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
4
5 4
6 4
6 7
2 3
Output
3
Explanation
A valid chain is (2,3) -> (5,4) -> (6,7) of length 3. Equal widths cannot nest.