문제
새해를 맞아, 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순열
이 조건을 만족하는 모든
입력
첫 줄에 세 정수
출력
부분문제
| 번호 | 점수 | 조건 |
|---|---|---|
| #1 | 28점 | |
| #2 | 21점 | |
| #3 | 21점 | |
| #4 | 30점 | 추가 제약 조건이 없다. |
예제 #1
3 0 192603497
1 2 3
여기서 가능한 순열은
예제 #2
3 1 144408983
3 4 4
여기서 가능한 두 순열은