From 1dce00355f218709f259a3775d52d1c08d22011b Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Sat, 13 Dec 2025 16:24:27 +0900 Subject: [PATCH] =?UTF-8?q?[20251213]=20BOJ=20/=20G5=20/=20=EC=A7=84?= =?UTF-8?q?=EC=9A=B0=EC=9D=98=20=EB=8B=AC=20=EC=97=AC=ED=96=89=20(Large)?= =?UTF-8?q?=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3\254 \354\227\254\355\226\211 (Large).md" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "JHLEE325/202512/13 BOJ G5 \354\247\204\354\232\260\354\235\230 \353\213\254 \354\227\254\355\226\211 (Large).md" diff --git "a/JHLEE325/202512/13 BOJ G5 \354\247\204\354\232\260\354\235\230 \353\213\254 \354\227\254\355\226\211 (Large).md" "b/JHLEE325/202512/13 BOJ G5 \354\247\204\354\232\260\354\235\230 \353\213\254 \354\227\254\355\226\211 (Large).md" new file mode 100644 index 00000000..fd1d9e8f --- /dev/null +++ "b/JHLEE325/202512/13 BOJ G5 \354\247\204\354\232\260\354\235\230 \353\213\254 \354\227\254\355\226\211 (Large).md" @@ -0,0 +1,58 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static final int INF = 1_000_000_000; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + + int[][] cost = new int[N][M]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + cost[i][j] = Integer.parseInt(st.nextToken()); + } + } + + int[][][] dp = new int[N][M][3]; + + for (int j = 0; j < M; j++) { + for (int d = 0; d < 3; d++) { + dp[0][j][d] = cost[0][j]; + } + } + + for (int i = 1; i < N; i++) { + for (int j = 0; j < M; j++) { + Arrays.fill(dp[i][j], INF); + + if (j + 1 < M) { + dp[i][j][0] = Math.min(dp[i - 1][j + 1][1], dp[i - 1][j + 1][2]) + cost[i][j]; + } + + dp[i][j][1] = Math.min(dp[i - 1][j][0], dp[i - 1][j][2]) + cost[i][j]; + + if (j - 1 >= 0) { + dp[i][j][2] = Math.min(dp[i - 1][j - 1][0], dp[i - 1][j - 1][1]) + cost[i][j]; + } + } + } + + int answer = INF; + for (int j = 0; j < M; j++) { + for (int d = 0; d < 3; d++) { + answer = Math.min(answer, dp[N - 1][j][d]); + } + } + + System.out.println(answer); + } +} +```