문제) 백준 - DP(동적 계획법) - 벼락치기
https://www.acmicpc.net/problem/14728
14728번: 벼락치기
ChAOS(Chung-ang Algorithm Organization and Study) 회장이 되어 일이 많아진 준석이는 시험기간에도 일 때문에 공부를 하지 못하다가 시험 전 날이 되어버리고 말았다. 다행히도 친절하신 교수님께서 아래와
www.acmicpc.net
한정된 시간에 최대 점수를 내기 위해 선택해야하는 전형적인 냅색(배낭) 문제.
DP(인덱스, 남은 공부 시간)으로 해결할 수 있다.
C++ 소스코드)
This file contains 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
int solve(int idx, int T) { | |
if (idx == N) return 0; | |
int& ret = cache[idx][T]; | |
if (ret != -1)return ret; | |
// PASS | |
ret = solve(idx + 1, T); | |
// Study | |
if (T >= StudyTime[idx]) | |
ret = max(ret, solve(idx + 1, T - StudyTime[idx]) + Score[idx]); | |
return ret; | |
} |
Full Code)
GitHub - Chocochip101/BOJ_Solution
Contribute to Chocochip101/BOJ_Solution development by creating an account on GitHub.
github.com
반응형
'PS(Problem Solving) > 백준_BOJ' 카테고리의 다른 글
[백준] 11060번 - 점프 점프 (C++) 문제 및 풀이 (0) | 2021.11.04 |
---|---|
[백준] 9507번 - Generations of Tribbles (C++) 문제 및 풀이 (0) | 2021.11.03 |
[백준] 13565번 - 침투 (C++) 문제 및 풀이 (0) | 2021.11.01 |
[백준] 14890번 - 경사로 (C++) 문제 및 풀이 (0) | 2021.10.31 |
[백준] 23251번 - 스물셋 (C++) 문제 및 풀이 (0) | 2021.10.25 |
댓글