728x90
반응형
# 틀린 코드
n = int(input()) # 2<= n <= 1000
cost = [0]*(n+1)
for i in range(1,n+1):
cost[i] = list(map(int,input().split()))
# 집 마다 칠하는 비용이 다름!
id = [0 for i in range(n+1)]
id[0] = cost[1].index(max(cost[1]))
total=0
for i in range(1,n+1):
id[i] = cost[i].index(min(cost[i]))
if (id[i]==id[i-1]) :
id[i] = cost[i].index( min ( cost[i][ (id[i]+1)%3 ], cost[i][ (id[i]+2)%3 ]) )
total += cost[i][ id[i] ]
print(total)
# 정답
n = int(input())
cost = []
for i in range(n):
cost.append(list(map(int, input().split())))
for i in range(1, len(p)):
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][0], cost[i - 1][1]) + cost[i][2]
print(min(cost[n - 1][0], cost[n - 1][1], cost[n - 1][2]))
728x90
반응형
'백준 > 다이나믹 프로그래밍' 카테고리의 다른 글
# 1932 정수 삼각형 (0) | 2020.09.11 |
---|---|
# 2579 계단 오르기 (0) | 2020.09.11 |
# 11726 2xn 타일링 (0) | 2020.09.11 |
# 1003 피보나치 함수 (0) | 2020.09.11 |
# 1463 1로 만들기 (0) | 2020.09.11 |