[20250927] BOJ / P2 / 인생은 B와 D 사이의 C다 / 권혁준#992
Merged
ShinHeeEul merged 1 commit intomainfrom Sep 27, 2025
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/26602
🧭 풀이 시간
50분
👀 체감 난이도
✏️ 문제 설명
정점 N개인 트리가 있다.
리프 정점에 추가 정점을 하나 붙이는 데 드는 비용은 B이고, 리프 정점을 하나 떼는 비용은 D이다.
이 트리를
포화 이진 트리로 만드는 최소 비용을 구해보자.🔍 풀이 방법
정답이 되는 트리의 높이는 최대 34이다.
35를 넘어가면 항상 34 이하로 비용을 더 적게하여 만들 수 있다.
dp[n][h] = n을 루트로 하는 서브트리를 높이 h인 포화 이진 트리로 만드는 최소 비용이라고 정의하고, dfs를 돌려서 dp를 계산해줬다.
dp[n][h]를 구할 때는 n의 자식들 i에 대해 dp[i][h-1]을 가져오거나, 정점이 모자라면 붙이는 행위를 해서 dp를 계산했다.
⏳ 회고
높이 상한만 잘 구하면 그 다음은 할 만한거 같다