Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/28080
🧭 풀이 시간
20분
👀 체감 난이도
✏️ 문제 설명
정점 N개인 이진 트리가 주어지며, 각 정점에는 1 이상 M이하의 정수가 하나씩 적혀있다.
일부 정점에는 수가 지워져 있다.
수가 지워진 정점들에 1이상 M이하의 정수를 채워넣어 트리를 BST로 만드는 경우의 수를 구해보자.
🔍 풀이 방법
BST가 되려면 트리를 중위 순회했을 때 오름차순이 되어야 한다.
주어진 트리를 중위 순회하면 -1들이 섞여 나오게 되는데, -1이 연속한 구간을 묶어서 (-1의 개수, 사용 가능한 수의 개수) = (n, k)로 나타낸다.
이 때 -1에 수를 적절히 배치하는 경우의 수는 kCn이다.
생기는 구간들에 수를 배치할 때는 구간별로 서로 영향을 주지 않으니까 경우의 수를 싹 다 곱하면 된다.
⏳ 회고
예외 처리 주의