For Programmer

백준 2096번 파이썬 문제풀이(내려가기) - dp 본문

코팅테스트/백준 문제 모음

백준 2096번 파이썬 문제풀이(내려가기) - dp

유지광이 2022. 4. 12. 23:52
728x90


 

import sys

input = sys.stdin.readline

N = int(input())

dp = [[0, 0, 0], [0, 0, 0]]
dp2 = [[1e6, 1e6, 1e6], [0, 0, 0]]
idx = 0

for i in range(1, N + 1):
    arr = list(map(int, input().split()))
    for j in range(3):
        dp2[idx][j] = 1e6
        for k in range(3):
            if abs(j - k) >= 2:
                continue

            dp[idx][j] = max(dp[idx][j], dp[not idx][k] + arr[j])
            dp2[idx][j] = min(dp2[idx][j], dp2[not idx][k] + arr[j])

    idx = not idx

print(max(dp[not idx]), min(dp2[not idx]))
728x90
Comments