728x90
https://www.acmicpc.net/problem/11048
// 코드
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
|
import java.util.*;
import java.io.*;
public class Main {
// main
public static void main(String[] args) throws Exception{
// Please Enter Your Code Here
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] arr = new int[N][];
for(int i=0; i<N; ++i) arr[i] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
// dp테이블을 채운다.
int[][] dp = new int[N+1][M+1];
// 각 위치에 최댓값을 넣어준다.
for(int row=1; row<N+1; ++row) for(int col=1; col<M+1; ++col) dp[row][col] = arr[row-1][col-1] + Math.max( dp[row-1][col], dp[row][col-1] );
bw.write(String.valueOf( dp[N][M] ));
bw.flush();
bw.close();
br.close();
}
}
|
cs |
반응형