[20251125] BOJ / P5 / 플레이리스트 / 이종환 #1505
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/12872
🧭 풀이 시간
90분
👀 체감 난이도
✏️ 문제 설명
수빈이는 BOJ 알고리즘 캠프에서 음악을 들으면서 문제를 풀고 있다. 지금 수빈이의 스마트폰에는 N개의 노래가 저장되어 있다. 오늘 수빈이는 P개의 노래를 들으려고 한다. 수빈이는 다음과 같은 조건을 만족하는 플레이리스트를 만들려고 한다. 플레이리스트에는 같은 노래를 여러 번 추가해도 된다.
모든 노래를 플레이리스트에 추가해야 한다.
같은 노래를 추가하려면, 플레이리스트에서 두 노래 사이에 적어도 M개의 곡이 있어야 한다.
수빈이는 플레이리스트를 만들 수 있는 경우의 수가 궁금해졌다. N, M, P가 주어졌을 때, 수빈이가 만들 수 있는 플레이리스트의 경우의 수를 구하는 프로그램을 작성하시오.
🔍 풀이 방법
딱 보자마자 dp인 것은 알았지만, 로직을 찾아내는데 한참 걸렸다.
우선 노래마다 차이점이 존재하는 것이 아니고, 결국 모든 노래를 한 번씩은 사용해야하기에,
dp[i][j]: i번째자리까지 j개의 숫자로 채우는 경우의 수
이렇게 지정하고 접근하였다.
이때 간격만큼의 부분배열에는 겹치는게 없다는 것을 이용하였다.
⏳ 회고