-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ1932.java
More file actions
32 lines (26 loc) · 785 Bytes
/
BOJ1932.java
File metadata and controls
32 lines (26 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package quki.algorithm.dp;
import java.util.Scanner;
public class BOJ1932 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[][] = new int[n + 1][n + 1];
int d[][] = new int[n + 1][n + 1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
a[i][j] = sc.nextInt();
}
}
d[1][1] = a[1][1];
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
d[i][j] = Math.max(d[i-1][j-1], d[i-1][j]) +a[i][j];
}
}
int sum = -1;
for(int i = 1; i<=n;i++){
sum = Math.max(d[n][i], sum);
}
System.out.println(sum);
}
}