forked from GreatAlgorithm-Study/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJY_12913.java
More file actions
31 lines (25 loc) · 695 Bytes
/
JY_12913.java
File metadata and controls
31 lines (25 loc) · 695 Bytes
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.*;
class JY_12913 {
int solution(int[][] land) {
int answer = 0;
int N = land.length;
int[][] dp = new int[N][4];
// 초기화
for(int j=0; j<4; j++){
dp[0][j] = land[0][j];
}
for(int i=1; i<N; i++){
for(int j=0; j<4; j++) {
for(int k = 0; k<4; k++){
if(j != k){
dp[i][j] = Math.max(dp[i][j], dp[i-1][k]+land[i][j]);
}
}
}
}
for(int j=0; j<4; j++){
answer = Math.max(answer, dp[N-1][j]);
}
return answer;
}
}