-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ1932.java
More file actions
41 lines (33 loc) · 1.17 KB
/
BOJ1932.java
File metadata and controls
41 lines (33 loc) · 1.17 KB
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
33
34
35
36
37
38
39
40
41
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ1932 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[][] dp = new int[n+1][n+1];
for(int i = 0; i < n; i++){
StringTokenizer st = new StringTokenizer(br.readLine());
for(int j = 0; j < i+1; j++){
dp[i][j] = Integer.parseInt(st.nextToken());
}
}
for(int i = 1; i < n; i++){
for(int j = 0; j < n; j++){
if(j == 0){
dp[i][j] += dp[i-1][j];
}else if(j == n-1){
dp[i][j] += dp[i-1][j-1];
}else{
dp[i][j] += Math.max(dp[i-1][j-1], dp[i-1][j]);
}
}
}
int max = Integer.MIN_VALUE;
for(int arr : dp[n-1]){
max = Math.max(max, arr);
}
System.out.print(max);
}
}