From 9e38a56951344caed0bb71a42200ed2e442a3016 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Wed, 3 Dec 2025 22:52:21 +0900 Subject: [PATCH] =?UTF-8?q?[20251203]=20BOJ=20/=20G3=20/=20=EC=9A=95?= =?UTF-8?q?=EC=8B=AC=EC=9F=81=EC=9D=B4=20=ED=8C=90=EB=8B=A4=20/=20?= =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\354\235\264 \355\214\220\353\213\244.md" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "zinnnn37/202512/3 BOJ G3 \354\232\225\354\213\254\354\237\201\354\235\264 \355\214\220\353\213\244.md" diff --git "a/zinnnn37/202512/3 BOJ G3 \354\232\225\354\213\254\354\237\201\354\235\264 \355\214\220\353\213\244.md" "b/zinnnn37/202512/3 BOJ G3 \354\232\225\354\213\254\354\237\201\354\235\264 \355\214\220\353\213\244.md" new file mode 100644 index 00000000..d34ea80e --- /dev/null +++ "b/zinnnn37/202512/3 BOJ G3 \354\232\225\354\213\254\354\237\201\354\235\264 \355\214\220\353\213\244.md" @@ -0,0 +1,69 @@ +```java +import java.io.*; +import java.util.StringTokenizer; + +public class BJ_1937_욕심쟁이_판다 { + + private static final int[] dx = { 0, 1, 0, -1 }; + private static final int[] dy = { 1, 0, -1, 0 }; + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static StringTokenizer st; + + private static int N, ans; + private static int[][] bamboo, dp; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + ans = 0; + + bamboo = new int[N][N]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + bamboo[i][j] = Integer.parseInt(st.nextToken()); + } + } + dp = new int[N][N]; + } + + private static void sol() throws IOException { + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + ans = Math.max(ans, dfs(i, j)); + } + } + bw.write(ans + ""); + bw.flush(); + bw.close(); + br.close(); + } + + private static int dfs(int x, int y) { + if (dp[x][y] != 0) return dp[x][y]; + + dp[x][y] = 1; + + for (int d = 0; d < 4; d++) { + int nx = x + dx[d]; + int ny = y + dy[d]; + + if (OOB(nx, ny) || bamboo[x][y] >= bamboo[nx][ny]) continue; + + dp[x][y] = Math.max(dp[x][y], dfs(nx, ny) + 1); + } + return dp[x][y]; + } + + private static boolean OOB(int x, int y) { + return x < 0 || x >= N || y < 0 || y >= N; + } + +} +``` \ No newline at end of file