[20250705] BOJ / P5 / 대기업 승범이네 / 권혁준 #411
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/17831
🧭 풀이 시간
15분
👀 체감 난이도
✏️ 문제 설명
정점이 N개인 트리가 있다. 정점에 가중치가 있다.
부모-자식 관계로 멘토링을 형성할 수 있는데, 이 때 시너지의 값은 (부모 가중치) * (자식 가중치)이다.
한 정점은 하나의 멘토링에만 포함될 수 있을 때, 전체 시너지의 합을 최대화 해보자.
🔍 풀이 방법
두 종류의 DP를 준비한다.
dp1[n] = n번 정점을 루트로 하는 서브트리 내에서, n번 정점이 어떤 멘토링에도 포함되지 않는 경우의 최대 시너지 합
dp2[n] = n번 정점을 루트로 하는 서브트리 내에서, n번 정점이 누군가의 멘토인 경우의 최대 시너지 합
n의 자식들을 i라고 하면,
$dp1[n] = \sum{ \max(dp1[i], dp2[i])}$
$dp2[n] = dp1[n] + \max(dp[i][0] + A[i] * A[n] - \max(dp[i][0], dp[i][1]))$
이 성립한다.
⏳ 회고
난이도 기여 의견을 보니 2*n 타일 채우기 문제랑 비슷하다는데, 잘 모르겠다..