programming/Algorithm

조립라인

Roien 2021. 12. 22.
반응형
import sys

N = int(sys.stdin.readline())

grid = [[0]*2 for _ in range(N)]
tran = [[0]*2 for _ in range(N)]

for i in range(N - 1):
    A, B, AB, BA = map(int, sys.stdin.readline().split())
    grid[i][0] = A
    grid[i][1] = B
    tran[i][0] = AB
    tran[i][1] = BA

AN, BN = map(int, sys.stdin.readline().split())

grid[-1][0] = AN
grid[-1][1] = BN

for i in range(N - 1):
    grid[i + 1][0] += min(grid[i][0], grid[i][1] + tran[i][1])
    grid[i + 1][1] += min(grid[i][0] + tran[i][0], grid[i][1])

print(min(grid[-1]))

 

 

반응형

댓글