https://school.programmers.co.kr/learn/courses/30/lessons/12913
dp
class Solution {
static int ROW, COL;
static int answer = 0;
static int[][] box;
int solution(int[][] land) {
ROW = land.length;
COL = land[0].length;
box = land;
int[][] dp = new int[ROW][COL];
for(int c = 0; c < COL; c++){
dp[0][c] = box[0][c];
}
for(int r = 1; r < ROW; r++) {
for(int c = 0; c < COL; c++){
for(int j = 0; j < COL; j++){
if(c==j)continue;
dp[r][c] = Math.max(box[r][c] + dp[r-1][j], dp[r][c]);
}
}
}
for(int c = 0; c < COL; c++) {
answer = Math.max(dp[ROW-1][c], answer);
}
return answer;
}
}
[프로그래머스] 디스크 컨트롤러 (0) | 2025.02.04 |
---|---|
[프로그래머스] 가장 큰 수 (0) | 2025.02.04 |
[프로그래머스] [3차] 압축 (0) | 2025.02.04 |
[백준] 14426: 접두사 (0) | 2025.02.03 |
[프로그래머스] 방문길이 (0) | 2025.02.03 |