문제) 백준 - 동적 계획법 - 마라톤 2
https://www.acmicpc.net/problem/10653
10653번: 마라톤 2
젖소 박승원이 2번째 와 4번째 체크포인트를 건너뛸경우 경로는 (0,0) -> (1,1) -> (2,2) 로 4가 된다. 이보다 더 짧게 달릴수는 없다.
www.acmicpc.net
모든 체크 포인트의 좌표를 입력 받아 거리를 미리 계산합니다. 그 후, 체크 포인트를 뛰어넘는 경우와 그렇지 않는 경우로 각 최소 거리를 계산합니다.
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 ck) { | |
if (idx == 0) return 0; | |
int& ret = cache[idx][ck]; | |
if (ret != -1) return ret; | |
ret = INF; | |
for (int i = 0; i <= ck; ++i) | |
if(idx - i - 1 >= 0) | |
ret = min(ret, solve(idx - 1 - i, ck - i) + dist[idx -1 -i][idx]); | |
return ret; | |
} |
Full Code)
GitHub - Chocochip101/BOJ_Solution: BOJ Solutions
BOJ Solutions. Contribute to Chocochip101/BOJ_Solution development by creating an account on GitHub.
github.com
반응형
'PS(Problem Solving) > 백준_BOJ' 카테고리의 다른 글
[백준] 2745번 - 진법 변환 (C++) 문제 및 풀이 (0) | 2022.01.18 |
---|---|
[백준] 18312 - 시간 (C++) 문제 및 풀이 (0) | 2022.01.17 |
[백준] 19942번 - 다이어트 (C++) 문제 및 풀이 (0) | 2022.01.16 |
[백준] 2629번 - 양팔저울 (C++) 문제 및 풀이 (0) | 2022.01.15 |
[백준] 20365번 - 블로그2 (C++) 문제 및 풀이 (0) | 2022.01.14 |
댓글