[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๋ ๋ฐ๋จน๊ธฐ (์๋ฐ java)
1. ๋ฌธ์ : https://school.programmers.co.kr/learn/courses/30/lessons/12913
2. ํ์ด
์์ ํ์์ผ๋ก ํ์์ง๋ง ์๊ฐ์ด๊ณผ
dp๋ก ์ด์ ํ์์์ ์ต๋๊ฐ์ ํด๋น ํ์ ๋ํด์ฃผ๋ ์์ผ๋ก dp ๊ฐ ์ ๋ฐ์ดํธํ๋ฉฐ ๋ง์ง๋ง์ ๋น๊ตํ๋ ํ์ด
3. ์ฝ๋
class Solution {
int solution(int[][] land) {
int answer = 0;
for(int i=1; i<land.length; i++){
land[i][0] += Math.max(land[i-1][1], Math.max(land[i-1][2], land[i-1][3]));
land[i][1] += Math.max(land[i-1][0], Math.max(land[i-1][2], land[i-1][3]));
land[i][2] += Math.max(land[i-1][0], Math.max(land[i-1][1], land[i-1][3]));
land[i][3] += Math.max(land[i-1][0], Math.max(land[i-1][1], land[i-1][2]));
}
for(int i=0; i<4; i++){
answer = Math.max(answer, land[land.length-1][i]);
}
return answer;
}
}
'๐ป Coding Problems Solving > Dynamic Programming' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode] Maximum Product Subarray (0) | 2023.03.28 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 2*n ํ์ผ๋ง (์๋ฐ java) (0) | 2023.03.15 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๋ฉ๋ฆฌ ๋ฐ๊ธฐ (์๋ฐ java) (0) | 2023.01.12 |
[LeetCode] Maximum Subarray (0) | 2022.07.24 |
[LeetCode] Climbing Stairs (0) | 2022.07.09 |
์ต๊ทผ๋๊ธ