Skip to content

Conversation

@oncsr
Copy link
Contributor

@oncsr oncsr commented Apr 4, 2025

🧷 문제 링크

https://www.acmicpc.net/problem/1772

🧭 풀이 시간

30분

👀 체감 난이도

✏️ 문제 설명

정점 N개인 트리가 주어진다.
가지치기를 해서 간선을 하나 끊으면, 나눠진 두 부분 중 한 부분만 남길 수 있다.
정점을 정확히 M개 남기는 최소 가지치기 횟수를 구해보자.

🔍 풀이 방법

[사용한 알고리즘]

  • 배낭 DP
  • 트리 DP

1번 점을 루트로 잡고, dp식을 다음과 같이 정의했다.
dp[n][k] = n번 점을 루트로 하는 서브트리에서 k개의 정점만 남길 때 필요한 최소 가지치기 횟수

이 값은 자식 정점들의 dp값으로부터 배낭 문제 해결법을 통해 채워넣을 수 있다.
DFS로 이 dp값들을 구해줬다.

⏳ 회고

배낭을 떠올리니 난이도가 절반이 되었다

@oncsr oncsr added the success 👍 해설을 보지 않고 풀었을 때 label Apr 4, 2025
@ShinHeeEul ShinHeeEul merged commit 55ebde6 into main Apr 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

success 👍 해설을 보지 않고 풀었을 때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants