https://school.programmers.co.kr/learn/courses/30/lessons/43105
import java.util.*;
class Solution {
int[][] map;
int[][] dp;
public int solve(int x, int y) {
//기저조건
if (x == dp.length - 1)
return map[x][y];
if (dp[x][y] != -1)
return dp[x][y];
//다음 노드로 이동
int res = map[x][y];
res += Math.max(solve(x+1, y), solve(x+1, y+1));
return dp[x][y] = res;
}
public int solution(int[][] triangle) {
//초기화
map = triangle;
dp = new int[triangle.length][triangle[triangle.length - 1].length];
for (int i = 0; i < triangle.length; i++)
Arrays.fill(dp[i], -1);
return solve(0, 0);
}
}