[20250928] BOJ / G5 / 알약 / 이준희 #996
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/4811
🧭 풀이 시간
50분
👀 체감 난이도
✏️ 문제 설명
매일매일 약 반알을 먹는 할아버지가 있고, 온전한 약 한알을 반으로 나눠서 먹은 후에는 다시 병에 집어넣습니다.
이 때 알약 한조각을 꺼내는 날에는 W, 반쪽자리를 꺼내는 날에는 H 라고 쓸 때
알약 N개를 전부 먹었을 때 가능한 문자열의 가짓수를 구하는 문제입니다.
🔍 풀이 방법
2차원 DP를 이용해서 풀었습니다.
dp[w][h] 인 경우가 온전한 알약 w개, 반쪽자리 h개가 있는 경우의 문자열의 가짓수이고
재귀를 이용하여 계속 2차원 배열 값을 갱신했습니다.
수가 커서 메모이제이션을 활용해서 시간을 줄였습니다.
⏳ 회고
시간도 없어서 만만하게 봤다가 생각보다 어려웠던 문제였던 것 같습니다.
큰 수 + 여러 케이스 때문에 long, 메모이제이션을 활용했어야 했습니다.