File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.util.* ;
3+ import java.io.* ;
4+
5+ public class Main {
6+ static int N ;
7+ static int M ;
8+
9+ public static void main (String [] args ) throws IOException {
10+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
11+ StringTokenizer st = new StringTokenizer (br. readLine());
12+ N = nextInt(st);
13+ M = nextInt(st);
14+ int [][] arr = new int [M ][N ];
15+ int [][] dp = new int [M ][N ];
16+ for (int i = 0 ; i < M ; i++ ) {
17+ st = new StringTokenizer (br. readLine());
18+ for (int j = 0 ; j < N ; j++ ) {
19+ arr[i][j] = nextInt(st);
20+ if (j == 0 ) {
21+ dp[i][0 ] = arr[i][j];
22+ }
23+ }
24+ }
25+ for (int i = 1 ; i < N ; i++ ) {
26+ for (int j = 0 ; j < M ; j++ ) {
27+ int max = Integer . MIN_VALUE ;
28+ for (int k = 0 ; k < M ; k++ ) {
29+ if (k == j) max = Math . max(max, dp[k][i- 1 ] + arr[j][i]/ 2 );
30+ else max = Math . max(max, dp[k][i- 1 ] + arr[j][i]);
31+ }
32+ dp[j][i] = max;
33+ }
34+ }
35+
36+ int answer = Integer . MIN_VALUE ;
37+ for (int i = 0 ; i < M ; i++ ) {
38+ answer = Math . max(answer, dp[i][N - 1 ]);
39+ }
40+ System . out. println(answer);
41+ }
42+
43+ private static int nextInt (StringTokenizer st ) {
44+ return Integer . parseInt(st. nextToken());
45+ }
46+ }
47+ ```
48+
You can’t perform that action at this time.
0 commit comments