백준 1149 RGB거리

치즈말랑이·2022년 3월 29일

https://www.acmicpc.net/problem/1149

dp문제는 진짜 알다가도 모르겠다
이건 해설봤다..
https://pacific-ocean.tistory.com/147

import sys

N = int(sys.stdin.readline().strip())
cost = []
for _ in range(N):
    cost.append(list(map(int, sys.stdin.readline().strip().split())))
print(cost)
# cost[n][0] : 빨강
# cost[n][1] : 초록
# cost[n][2] : 파랑
total_cost = []
cost_add = 0
for i in range(1, N):
    cost[i][0] += min(cost[i-1][1], cost[i-1][2])
    cost[i][1] += min(cost[i-1][0], cost[i-1][2])
    cost[i][2] += min(cost[i-1][0], cost[i-1][1])
    print(cost)
print(min(cost[N-1][0], cost[N-1][1], cost[N-1][2]))

dp에 대해서 제대로 이해하지 못하고 있는것같다.
아니면 이 문제를 이해하지 못했거나

profile
공부일기

0개의 댓글