rueki
프로그래머스 LV2. 땅따먹기 본문
728x90
반응형
- C ++
#include <iostream>
#include <vector>
using namespace std;
int solution(vector<vector<int> > land)
{
int answer = 0;
for(int i = 0 ; i < land.size() - 1; i++)
{
land[i+1][0] += max(land[i][1], max(land[i][2], land[i][3]));
land[i+1][1] += max(land[i][0], max(land[i][2], land[i][3]));
land[i+1][2] += max(land[i][0], max(land[i][1], land[i][3]));
land[i+1][3] += max(land[i][0], max(land[i][1], land[i][2]));
}
answer = max(land[land.size()-1][0], max(land[land.size()-1][1], max( land[land.size()-1][2],
land[land.size()-1][3] )));
return answer;
}
- python
def solution(land):
for i in range(1, len(land)):
for j in range(len(land[0])):
land[i][j] = max(land[i -1][: j] + land[i - 1][j + 1:]) + land[i][j]
return max(land[-1])
728x90
반응형
'프로그래머스 연습' 카테고리의 다른 글
프로그래머스 LV2. 영어 끝말잇기 (0) | 2022.10.09 |
---|---|
프로그래머스 LV2. 숫자의 표현 (0) | 2022.10.08 |
프로그래머스 LV2. 괄호회전하기 (0) | 2022.10.07 |
프로그래머스 LV2. 최대값과 최솟값 (0) | 2022.10.07 |
프로그래머스 LV2 멀리뛰기(DP) (0) | 2022.10.07 |
Comments