Skip to content

Commit d488568

Browse files
authored
Merge pull request #62 from solid-connection/JAEHEE25
[Week09] BOJ 1446: 지름길
2 parents 51a4457 + 3ad461d commit d488568

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package week09.BOJ_1446_지름길;
2+
3+
import java.util.*;
4+
import java.lang.*;
5+
import java.io.*;
6+
7+
class BOJ1446 {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
StringTokenizer st = new StringTokenizer(br.readLine());
11+
int N = Integer.parseInt(st.nextToken());
12+
int D = Integer.parseInt(st.nextToken());
13+
int[][] shortcut = new int[N][3];
14+
15+
for (int i = 0; i < N; i++) {
16+
st = new StringTokenizer(br.readLine());
17+
int start = Integer.parseInt(st.nextToken());
18+
int end = Integer.parseInt(st.nextToken());
19+
int dist = Integer.parseInt(st.nextToken());
20+
shortcut[i][0] = start;
21+
shortcut[i][1] = end;
22+
shortcut[i][2] = dist;
23+
}
24+
25+
int[] dp = new int[D+1];
26+
Arrays.fill(dp, Integer.MAX_VALUE);
27+
dp[0] = 0;
28+
29+
for (int i = 1; i <= D; i++) {
30+
for (int j = 0; j < N; j++) { //지름길 확인
31+
if (shortcut[j][1] == i) { //해당 위치에 도착하는 지름길이 있을 경우
32+
dp[i] = Math.min(dp[i], Math.min(dp[i-1] + 1, dp[shortcut[j][0]] + shortcut[j][2]));
33+
} else { // 없을 경우
34+
dp[i] = Math.min(dp[i], dp[i-1] + 1);
35+
}
36+
}
37+
}
38+
System.out.println(dp[D]);
39+
}
40+
}

0 commit comments

Comments
 (0)