티스토리 뷰
https://www.acmicpc.net/problem/1149
1149번: RGB거리
첫째 줄에 집의 수 N(2 ≤ N ≤ 1,000)이 주어진다. 둘째 줄부터 N개의 줄에는 각 집을 빨강, 초록, 파랑으로 칠하는 비용이 1번 집부터 한 줄에 하나씩 주어진다. 집을 칠하는 비용은 1,000보다 작거나 같은 자연수이다.
www.acmicpc.net
import sys
N = int(sys.stdin.readline())
rgb = []
for i in range(N):
rgb.append(list(map(int, sys.stdin.readline().split())))
cost = [[0]*3 for _ in range(N)]
for i in range(N):
if i == 0:
cost[i][0] = rgb[0][0]
cost[i][1] = rgb[0][1]
cost[i][2] = rgb[0][2]
cost[i][0] = min(cost[i-1][1], cost[i-1][2]) + rgb[i][0]
cost[i][1] = min(cost[i-1][0], cost[i-1][2]) + rgb[i][1]
cost[i][2] = min(cost[i-1][0], cost[i-1][1]) + rgb[i][2]
print(min(cost[N-1]))'Algorithm > Baekjoon' 카테고리의 다른 글
| [백준] 2231 : 분해합 (0) | 2020.03.13 |
|---|---|
| [백준] 2798 : 블랙잭 - Python (0) | 2020.03.13 |
| [백준] 1110 : 더하기 사이클 - Python (0) | 2020.03.12 |
| [백준] 9461 : 파도반 수열 - Python (0) | 2020.03.12 |
| [백준] 1904 : 01타일 - Python (0) | 2020.03.11 |
