-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
29 lines (23 loc) · 703 Bytes
/
Main.java
File metadata and controls
29 lines (23 loc) · 703 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
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[][] arr = new int[N+1][N+1];
for(int i=1; i<N+1; i++){
for(int j=1; j<i+1; j++){
arr[i][j] = sc.nextInt();
}
}
int[][] dp = new int[N+1][N+1];
for(int i=1; i<N+1; i++){
for(int j=1; j<i+1; j++){
dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-1]) + arr[i][j];
}
}
int max = Arrays.stream(dp[N]).max().getAsInt();
System.out.println(max);
sc.close();
}
}