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/1126
🧭 풀이 시간
90분
👀 체감 난이도
✏️ 문제 설명
블럭을 두 그룹으로 쌓을 껀데 두 탑의 높이를 같게 하려고 함. 이 때 탑의 높이의 최댓값
🔍 풀이 방법
첫 번째 접근 방식
dp[i] = i의 높이를 갖는 탑들의 모든 경우의 수(index를 담음)으로 상태를 정의했다. 답을 찾을 땐, 가장 높은 높이부터 내림차순으로 탐색하고 각 탑들의 집합이 서로소일 경우 답을 내는 방식을 사용했다. 이 방법으로 구현하면서 불안했던 점은 dp[i]의 원소로 몇 개의 탑의 경우의 수가 쌓일지 모르는 점이었다. N과 모든 조각의 높이의 합이 500000을 넘지 않길래 '운 좋으면 되겠다.'라는 생각에 풀었는데 메모리 초과가 발생했다.두 번째 접근 방식
dp[i] = 두 탑의 높이 차가 i일 경우 더 높은 탑의 높이로 상태를 정의했다. 왜 같은 높이 차인 경우 더 높은 탑의 높이를 저장해도 될까? 문제를 풀 땐 그리디적으로 더 낫지 않을까? 라는 생각을 했다.이렇게 정의하니 더 높은 탑의 높이를 저장해야 했다. 우리는 dp를 계산할 때 중복을 피하기 위해 뒤에서 부터 검사한다. 하지만 이 DP 연산은 한 방향으로만 갱신하지 않기 때문에
newDp를 사용한다.의 경우의 수로 나눠서 구현하니 직관적이고 문제를 단순하게 정의할 수 있었다.
⏳ 회고
dp[i] = 두 탑의 높이 차가 i일 경우 더 높은 탑의 높이로 상태를 정의하는 걸 처음 봤다. 이 방식은 두 탑의 높이도 알 수 있기 때문에 근거있는 상태 정의였다. 더 유연하게 생각해야 할 꺼 같고 그러려면 더 많은 문제를 접해야겠다.