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/3405
🧭 풀이 시간
80분
👀 체감 난이도
✏️ 문제 설명
N개의 왕국이 있고, D[a][b] = a왕국이 b왕국에게 빚진 금액이다.
어떤 왕국의 잔고가 음수라면, 양과 음의 부채를 모두 없애고 파산할 수 있다. (파산하는 순서에 따라 시나리오가 달라지게 된다.)
어떤 시나리오에서 단 하나의 왕국만이 파산하지 않았다면, 그 왕국은 유일한 생존국이 될 수 있다.
이러한 왕국을 모두 구해보자.
🔍 풀이 방법
dp[k] = 파산한 왕국 : 1, 생존한 왕국 : 0로 나타내었을 때, 비트마스킹 k인 시나리오가 가능한 경우인지? -> boolean으로 표현
위와 같이 dp를 세우고, bit DP를 탑다운으로 돌려주었다.
⏳ 회고
원래 dp[n][k]처럼 2차원으로 구현했었는데, 메모리 초과 | 시간 초과로 실패했다.
구현 방식을 보니까 차원 하나를 떼도 될 것 같아서 고친 뒤 해결했다.