Skip to content

[BOJ/실버1] 22-10-14 (RGB거리)#24

Merged
hyesuuou merged 1 commit into
mainfrom
hyesu
Oct 14, 2022
Merged

[BOJ/실버1] 22-10-14 (RGB거리)#24
hyesuuou merged 1 commit into
mainfrom
hyesu

Conversation

@hyesuuou

Copy link
Copy Markdown
Collaborator

🌱 문제번호와 링크

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

🥺 무엇을 알게 되었나요?

for _ in range(n):
    r, g, b = map(int, input().split())
    cost.append((r, g, b))

d[0][0] = cost[0][0]
d[0][1] = cost[0][1]
d[0][2] = cost[0][2]

for i in range(1, n):
    d[i][0] = min(d[i-1][1], d[i-1][2]) + cost[i][0]
    d[i][1] = min(d[i-1][0], d[i-1][2]) + cost[i][1]
    d[i][2] = min(d[i-1][0], d[i-1][1]) + cost[i][2]

마지막이 r일때, g일때, b일때를 모두 구해서
그중 가장 최솟값을 구한다.
d[i][_]는 i번째 집까지 칠했을 때 최소비용이니까
d[i][0] 마지막집이 r일때 i까지 칠했을때 최소비용임

@hyesuuou hyesuuou self-assigned this Oct 14, 2022
@hyesuuou hyesuuou merged commit b66bf8d into main Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant