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/32691
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
N명의 사람이 존재한다.
각 사람의 프로그래밍 실력은 A[i], 목표 등수는 B[i]이다.
아래 조건에 맞춰 팀을 구성한다.
팀 실력은 팀에 속한 3명의 프로그래밍 실력의 합이다.
팀을 적절히 구성해서 팀 실력의 합의 최댓값을 구해보자.
🔍 풀이 방법
목표 등수를 기준으로 사람들을 정렬하면, dp식을 떠올릴 수 있다.
dp[i] = i번째 사람을 팀의 마지막이 되도록 구성했을 때 팀 실력의 합의 최댓값그냥 저 식을 생각하면 O(N^2)으로 보인다.
dp[i] = max(dp[j] + (max1(A[j+1:i]) + max2(A[j+1:i]) + max3(A[j+1:i]))이기 때문이다.
하지만 여기서 j <= i-6이라면, j+1 ~ i 구간에서 팀이 두 개 이상 생겨버리게 된다.

이 경우는 이미 이전 dp계산 시에 고려된 경우라 생각하지 않아도 된다.
따라서 dp[i]를 계산할 때 고려해야 하는 케이스가 상수 시간으로 줄어들 게 되고, O(N)으로 dp배열 전체를 구할 수 있다.
⏳ 회고
O(N^2) -> O(N)으로 줄이는 아이디어가 중요한 듯