Problems
새해를 맞아, Farmer John은 소들에게 축제 분위기의 이진 탐색 트리(BST)를 선물하기로 했다!
BST를 생성하기 위해, FJ는 먼저 정수
generate(l,r):
if l > r, return empty subtree;
x = argmin_{l <= i <= r} a_i; // index of min a_i in {a_l,...,a_r}
return a BST with x as the root,
generate(l,x-1) as the left subtree,
generate(x+1,r) as the right subtree;예를 들어, 순열
4
/ \
2 5
/ \
1 3순열
이 조건을 만족하는 모든
Input
첫 줄에 세 정수
Output
Subtask
| # | Score | Condition |
|---|---|---|
| #1 | 28 | |
| #2 | 21 | |
| #3 | 21 | |
| #4 | 30 | 추가 제약 조건이 없다. |
Example #1
3 0 192603497
1 2 3
여기서 가능한 순열은
Example #2
3 1 144408983
3 4 4
여기서 가능한 두 순열은