Skip to content

Commit 4ad24be

Browse files
authored
Merge pull request #1573 from AlgorithmWithGod/zinnnn37
[20251203] BOJ / G3 / 욕심쟁이 판다 / 김민진
2 parents 9fde73f + 9e38a56 commit 4ad24be

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
```java
2+
import java.io.*;
3+
import java.util.StringTokenizer;
4+
5+
public class BJ_1937_욕심쟁이_판다 {
6+
7+
private static final int[] dx = { 0, 1, 0, -1 };
8+
private static final int[] dy = { 1, 0, -1, 0 };
9+
10+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
12+
private static StringTokenizer st;
13+
14+
private static int N, ans;
15+
private static int[][] bamboo, dp;
16+
17+
public static void main(String[] args) throws IOException {
18+
init();
19+
sol();
20+
}
21+
22+
private static void init() throws IOException {
23+
N = Integer.parseInt(br.readLine());
24+
ans = 0;
25+
26+
bamboo = new int[N][N];
27+
for (int i = 0; i < N; i++) {
28+
st = new StringTokenizer(br.readLine());
29+
for (int j = 0; j < N; j++) {
30+
bamboo[i][j] = Integer.parseInt(st.nextToken());
31+
}
32+
}
33+
dp = new int[N][N];
34+
}
35+
36+
private static void sol() throws IOException {
37+
for (int i = 0; i < N; i++) {
38+
for (int j = 0; j < N; j++) {
39+
ans = Math.max(ans, dfs(i, j));
40+
}
41+
}
42+
bw.write(ans + "");
43+
bw.flush();
44+
bw.close();
45+
br.close();
46+
}
47+
48+
private static int dfs(int x, int y) {
49+
if (dp[x][y] != 0) return dp[x][y];
50+
51+
dp[x][y] = 1;
52+
53+
for (int d = 0; d < 4; d++) {
54+
int nx = x + dx[d];
55+
int ny = y + dy[d];
56+
57+
if (OOB(nx, ny) || bamboo[x][y] >= bamboo[nx][ny]) continue;
58+
59+
dp[x][y] = Math.max(dp[x][y], dfs(nx, ny) + 1);
60+
}
61+
return dp[x][y];
62+
}
63+
64+
private static boolean OOB(int x, int y) {
65+
return x < 0 || x >= N || y < 0 || y >= N;
66+
}
67+
68+
}
69+
```

0 commit comments

Comments
 (0)