[20250716] BOJ / G4 / 다이어트 / 설진영 #481
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/19942
🧭 풀이 시간
25분
👀 체감 난이도
✏️ 문제 설명
N개의 식재료 중 일부를 선택해서 단백질, 지방, 탄수화물, 비타민의 최소 조건을 만족하면서 비용을 최소화하는 문제. 같은 비용이면 사전순으로 가장 빠른 조합을 출력해야 함.
🔍 풀이 방법
백트래킹으로 해결함. 선택 / 선택X 의 2가지 경우를 모두 탐색하되 가지치기로 최적화
조건 만족하면 즉시 종료
비용 초과하면 가지치기로 중단
처음에는 비트마스킹으로 풀었는데 사전순 처리가 복잡해서 백트래킹으로 변경함.
⏳ 회고
N≤15라서 완탐문제 같긴 했음
비트마스킹으로 풀려 했는데 백트래킹이 훨씬 깔끔하고 빠름