Skip to content

Commit fc64e2a

Browse files
committed
백제완: [BOJ] 1749 점수따먹기
1 parent 289ada0 commit fc64e2a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

BOJ/1000-5000번/JW_1749.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
public class JW_1749 {
2+
3+
public static void main(String[] args) throws Exception {
4+
int n = read(), m = read(), max = Integer.MIN_VALUE;
5+
int[][] dp = new int[n + 1][m + 1];
6+
for (int i = 1; i < n + 1; i++)
7+
for (int j = 1; j < m + 1; j++)
8+
// (i, j)까지의 누적합
9+
dp[i][j] = read() + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
10+
for (int i = 1; i < n + 1; i++)
11+
for (int j = 1; j < m + 1; j++)
12+
for (int k = 1; k < i + 1; k++)
13+
for (int l = 1; l < j + 1; l++) {
14+
// 부분 배열의 누적합 구하기
15+
max = Math.max(max, dp[i][j] - dp[k - 1][j] - dp[i][l - 1] + dp[k - 1][l - 1]);
16+
}
17+
System.out.println(max);
18+
}
19+
20+
private static int read() throws Exception {
21+
int c, n = System.in.read() & 15;
22+
boolean m = n == 13;
23+
if (m)
24+
n = System.in.read() & 15;
25+
while ((c = System.in.read()) >= 48)
26+
n = (n << 3) + (n << 1) + (c & 15);
27+
if (c == 13)
28+
System.in.read();
29+
return m ? ~n + 1 : n;
30+
}
31+
}

0 commit comments

Comments
 (0)