[20250404] BOJ / P3 / 정원 정리 / 권혁준 #296
Merged
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/1772
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
정점 N개인 트리가 주어진다.
가지치기를 해서 간선을 하나 끊으면, 나눠진 두 부분 중 한 부분만 남길 수 있다.
정점을 정확히 M개 남기는 최소 가지치기 횟수를 구해보자.
🔍 풀이 방법
[사용한 알고리즘]
1번 점을 루트로 잡고, dp식을 다음과 같이 정의했다.
dp[n][k] = n번 점을 루트로 하는 서브트리에서 k개의 정점만 남길 때 필요한 최소 가지치기 횟수이 값은 자식 정점들의 dp값으로부터 배낭 문제 해결법을 통해 채워넣을 수 있다.
DFS로 이 dp값들을 구해줬다.
⏳ 회고
배낭을 떠올리니 난이도가 절반이 되었다