From ac4cbf37103518e0c95e7b7cfa015d8d5fa01b40 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Thu, 30 Oct 2025 09:31:12 +0900 Subject: [PATCH] =?UTF-8?q?[20251030]=20BOJ=20/=20G3=20/=20=EB=82=B4?= =?UTF-8?q?=EB=A6=AC=EB=A7=89=20=EA=B8=B8=20/=20=EC=9D=B4=EC=A4=80?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\246\254\353\247\211 \352\270\270.md" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "JHLEE325/202510/30 BOJ G3 \353\202\264\353\246\254\353\247\211 \352\270\270.md" diff --git "a/JHLEE325/202510/30 BOJ G3 \353\202\264\353\246\254\353\247\211 \352\270\270.md" "b/JHLEE325/202510/30 BOJ G3 \353\202\264\353\246\254\353\247\211 \352\270\270.md" new file mode 100644 index 00000000..87e0c9a9 --- /dev/null +++ "b/JHLEE325/202510/30 BOJ G3 \353\202\264\353\246\254\353\247\211 \352\270\270.md" @@ -0,0 +1,55 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int M, N; + static int[][] map; + static int[][] dp; + static int[] dy = {-1, 1, 0, 0}; + static int[] dx = {0, 0, -1, 1}; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + M = Integer.parseInt(st.nextToken()); + N = Integer.parseInt(st.nextToken()); + + map = new int[M][N]; + dp = new int[M][N]; + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + dp[i][j] = -1; + } + } + + System.out.println(dfs(0, 0)); + } + + static int dfs(int y, int x) { + if (y == M - 1 && x == N - 1) { + return 1; + } + + if (dp[y][x] != -1) return dp[y][x]; + + dp[y][x] = 0; + + for (int dir = 0; dir < 4; dir++) { + int ny = y + dy[dir]; + int nx = x + dx[dir]; + + if (ny < 0 || nx < 0 || ny >= M || nx >= N) continue; + if (map[ny][nx] < map[y][x]) { + dp[y][x] += dfs(ny, nx); + } + } + + return dp[y][x]; + } +} +```