https://school.programmers.co.kr/learn/courses/30/lessons/12913
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
def solution(land):
for i in range(1, len(land)):
land[i][0] += max(land[i-1][1], land[i-1][2], land[i-1][3])
land[i][1] += max(land[i-1][0], land[i-1][2], land[i-1][3])
land[i][2] += max(land[i-1][0], land[i-1][1], land[i-1][3])
land[i][3] += max(land[i-1][0], land[i-1][1], land[i-1][2])
return max(land[-1])
DP(Dynamic Programmin) 알고리즘을 이용해야 한다.
단순히 각 행의 최댓값만을 더한다면 오히려 더 큰 해를 놓칠 수 있다.
각 원소의 최댓값에 대한 전체 행의 경우의 수를 확인하도록 한다.
'코딩테스트 > Python' 카테고리의 다른 글
| [프로그래머스][파이썬] 2 x n 타일링 (0) | 2023.12.30 |
|---|---|
| [프로그래머스][파이썬] 숫자 변환하기 (0) | 2023.12.29 |
| [프로그래머스][파이썬] 주식가격 (0) | 2023.12.20 |
| [프로그래머스][파이썬] 기능개발 (1) | 2023.12.11 |
| [프로그래머스][파이썬] 캐시 (1) | 2023.12.08 |