문제) 백준 - DP(동적 계획법) - 점프 점프
https://www.acmicpc.net/problem/11060
11060번: 점프 점프
재환이가 1×N 크기의 미로에 갇혀있다. 미로는 1×1 크기의 칸으로 이루어져 있고, 각 칸에는 정수가 하나 쓰여 있다. i번째 칸에 쓰여 있는 수를 Ai라고 했을 때, 재환이는 Ai이하만큼 오른쪽으로
www.acmicpc.net
cache[idx]: idx에서 n-1번 칸까지 갈 수 있는 최소 점프 횟수.
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) { | |
if (idx >= n) return INF; | |
if (idx == n - 1) return 0; | |
int& ret = cache[idx]; | |
if (ret != -1) return ret; | |
ret = INF; | |
for (int i = 1; i <= numbers[idx]; i++) | |
ret = min(ret, solve(idx + i) + 1); | |
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' 카테고리의 다른 글
[백준] 7579번 - 앱 (C++) 문제 및 풀이 (0) | 2021.11.07 |
---|---|
[백준] 12852번 - 1로 만들기 2 (C++) 문제 및 풀이 (0) | 2021.11.06 |
[백준] 9507번 - Generations of Tribbles (C++) 문제 및 풀이 (0) | 2021.11.03 |
[백준] 14728번 - 벼락치기 (C++) 문제 및 풀이 (0) | 2021.11.02 |
[백준] 13565번 - 침투 (C++) 문제 및 풀이 (0) | 2021.11.01 |
댓글