From 3ad461dfe771c04191181c979434b55c99cd89c6 Mon Sep 17 00:00:00 2001 From: JAEHEE25 Date: Thu, 5 Mar 2026 20:11:16 +0900 Subject: [PATCH] =?UTF-8?q?[Week09]=20BOJ=201446:=20=EC=A7=80=EB=A6=84?= =?UTF-8?q?=EA=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JAEHEE25.java" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "weekly/week09/BOJ_1446_\354\247\200\353\246\204\352\270\270/JAEHEE25.java" diff --git "a/weekly/week09/BOJ_1446_\354\247\200\353\246\204\352\270\270/JAEHEE25.java" "b/weekly/week09/BOJ_1446_\354\247\200\353\246\204\352\270\270/JAEHEE25.java" new file mode 100644 index 0000000..f71d820 --- /dev/null +++ "b/weekly/week09/BOJ_1446_\354\247\200\353\246\204\352\270\270/JAEHEE25.java" @@ -0,0 +1,40 @@ +package week09.BOJ_1446_지름길; + +import java.util.*; +import java.lang.*; +import java.io.*; + +class BOJ1446 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int D = Integer.parseInt(st.nextToken()); + int[][] shortcut = new int[N][3]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + int dist = Integer.parseInt(st.nextToken()); + shortcut[i][0] = start; + shortcut[i][1] = end; + shortcut[i][2] = dist; + } + + int[] dp = new int[D+1]; + Arrays.fill(dp, Integer.MAX_VALUE); + dp[0] = 0; + + for (int i = 1; i <= D; i++) { + for (int j = 0; j < N; j++) { //지름길 확인 + if (shortcut[j][1] == i) { //해당 위치에 도착하는 지름길이 있을 경우 + dp[i] = Math.min(dp[i], Math.min(dp[i-1] + 1, dp[shortcut[j][0]] + shortcut[j][2])); + } else { // 없을 경우 + dp[i] = Math.min(dp[i], dp[i-1] + 1); + } + } + } + System.out.println(dp[D]); + } +}