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/6101
🧭 풀이 시간
25분
👀 체감 난이도
✏️ 문제 설명
N마리의 소들에게 M종류의 음식을 제공하며, 각 소들은 선호하는 음식이 정해져있다.
소들이 서있는 순서대로 그룹화했을 때, 그룹의 비용은 해당 그룹에서 선호하는 음식의 합집합 크기의 제곱이다.
그룹의 비용 합을 최소화 해보자.
🔍 풀이 방법
비용 계산식에 따라, 한 그룹의 합집합 크기의 상한은 200이다. (sqrt(40000)이 200이기 때문)
그래서 dp[n][k]를 40000 * 200 크기로 잡고 dp식을 설계했다.
dp[n][k] = n번째 원소를 포함하는 합집합의 크기가 k인 경우의 최소 비용이걸 계산하려면 n번째 원소를 포함하는 크기 k인 합집합의 시작 인덱스를 O(1)에 알 수 있어야 한다.
그래서 카운팅 배열과 투 포인터로 미리 모든 (n,k)에 대한 시작 인덱스를 구해놓고 dp를 돌렸다.
⏳ 회고
ez