[20251031] BOJ / P5 / 이혼 / 권혁준 #1280
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/4160
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
집 N채를 두 사람이 나눠 가진다. 집은 각각 가치를 지닌다.
두 사람이 각각 집을 겹치지 않게 가져가고, 아무도 가져가지 않는 집이 있을 수도 있다.
아무도 가져가지 않는 집은 판다.
이때, 두 사람이 가져간 집의 가치 합은 각각 같아야 하고, 그런 경우가 여러 가지라면 각 사람이 가진 집의 가치 합을 가장 크게 가져간다.
팔아야 하는 집의 가치를 구해보자.
🔍 풀이 방법
N <= 24라 완탐을 돌리면 3^24가지 경우가 나와서 터진다.
그래서 집을 반으로 쪼개서 3^12가지 경우로 두 번 완탐을 돌린다.
완탐을 돌릴 때, 두 사람의 가치 합을 정수 하나로 표현하기 위해서 (A의 가치합) - (B의 가치합)으로 바꿔 저장하고 그 상태의 (A의 가치합) + (B의 가치합)을 Map에 기록한다.
두 쪽 결과를 각각 (c1, s1), (c2, s2)라고 하면, c1 + c2 = 0이 되는 s1 + s2의 최대를 구해서 답을 도출했다.
⏳ 회고
ez