PS/solved.ac
[CLASS 4]백준 1149번 - RGB거리
DawIT
2021. 3. 2. 02:34
320x100
1149번 : RGB거리
누구처럼 얼타지만 않는다면 쉽게 DP로 해결할 수 있을 만한 문제이다.
내 코드:
# dawitblog.tistory.com
from sys import stdin
input = stdin.readline
n = int(input())
cost = []
for _ in range(n):
cost.append(list(map(int,input().split())))
for i in range(1,n):
cost[i][0] = min(cost[i-1][1],cost[i-1][2]) + cost[i][0]
cost[i][1] = min(cost[i-1][0],cost[i-1][2]) + cost[i][1]
cost[i][2] = min(cost[i-1][1],cost[i-1][0]) + cost[i][2]
print(min(cost[n-1]))