Skip to content

Commit

Permalink
땅따먹기 - level2
Browse files Browse the repository at this point in the history
  • Loading branch information
sey2 authored Feb 28, 2023
1 parent db1c470 commit 88e1b9e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions programmers/땅따먹기.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
int solution(int[][] land) {
int answer = 0;

int dp[][] = new int[land.length][4];

for(int i=0; i<4; i++) dp[0][i] = land[0][i];

for(int i=1; i<land.length; i++){
for(int j=0; j<4; j++){

for(int k=0; k<4; k++){
if(j == k) continue;
dp[i][j] = Math.max(dp[i][j], land[i][j] + dp[i-1][k]);
}

}
}

for(int i=0; i<4; i++)
answer = Math.max(dp[dp.length-1][i], answer);


return answer;
}
}

0 comments on commit 88e1b9e

Please sign in to comment.