File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .util .*;
3
+
4
+ public class Main {
5
+
6
+ public static void main (String [] args ) throws IOException {
7
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
8
+ int n = Integer .parseInt (br .readLine ());
9
+ int [][] arr = new int [n +1 ][n +1 ];
10
+ for (int i =1 ; i <=n ; i ++) {
11
+ StringTokenizer st = new StringTokenizer (br .readLine ());
12
+ for (int j =1 ; j <=i ; j ++) {
13
+ arr [i ][j ] = Integer .parseInt (st .nextToken ());
14
+ }
15
+ }
16
+ int [][] d = new int [n +1 ][n +1 ];
17
+ for (int i =1 ; i <=n ; i ++) {
18
+ for (int j =1 ; j <=i ; j ++) {
19
+ d [i ][j ] = Math .max (d [i -1 ][j -1 ], d [i -1 ][j ]) + arr [i ][j ];
20
+ }
21
+ }
22
+ int answer = arr [1 ][1 ];
23
+ for (int i =1 ; i <=n ; i ++) {
24
+ answer = Math .max (answer , d [n ][i ]);
25
+ }
26
+ System .out .println (answer );
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments