728x90
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int[][] arr;
static Integer[][] dp;
static int N;
static int find(int height, int idx) {
if(height == N - 1)
return dp[height][idx];
if(dp[height][idx] == null) {
dp[height][idx] = Math.max(find(height + 1, idx), find(height + 1, idx + 1)) + arr[height][idx];
}
return dp[height][idx];
}
public static void main(String[] args) throws Exception, IOException {
StringTokenizer st;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
arr = new int[N][N];
dp = new Integer[N][N];
for(int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine(), " ");
for(int j = 0; j < i + 1; j++) {
arr[i][j] = Integer.parseInt(st.nextToken());
}
}
for(int i = 0; i < N; i++) {
dp[N - 1][i] = arr[N - 1][i];
}
System.out.println(find(0,0));
}
}
dp[0][0]으로 밑을 채워나가는 형식으로 해야되는 거였다!!!끄악!!
입력받는방법부터 틀려먹었다.. 이 문제는 다시 열심히 보기!
728x90
'CS > Algorithm' 카테고리의 다른 글
[백준 : 2156] 포도주 시식 (0) | 2021.05.16 |
---|---|
[백준 : 11726] 2 x n 타일링 - JAVA (0) | 2021.05.16 |
[백준 : 2579] 계단오르기 - java (0) | 2021.05.16 |
[백준 : 2156] 포도주 시식 - java (0) | 2021.05.16 |
[백준 : 11053] 가장 긴 증가하는 부분 수열 (0) | 2021.05.16 |