[BOJ] 1149번 RGB거리

yeham·2022년 11월 14일
0

백준

목록 보기
13/22

문제

RGB거리

코드

#include <iostream>
#include <cmath>

using namespace std;

int color[1001][3];
int house[1001][3];
int n;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 3; j++)
			cin >> color[i][j];
	
	house[0][0] = color[0][0]; // r
	house[0][1] = color[0][1]; // g
	house[0][2] = color[0][2]; // b
	
	for (int i = 1; i <= n; i++)
	{
		house[i][0] = min(house[i - 1][1], house[i - 1][2]) + color[i][0];
		house[i][1] = min(house[i - 1][0], house[i - 1][2]) + color[i][1];
		house[i][2] = min(house[i - 1][0], house[i - 1][1]) + color[i][2];
	}

	if (house[n][0] >= house[n][1])
		cout << min(house[n][1], house[n][2]);
	else if (house[n][1] >= house[n][2])
		cout << min(house[n][2], house[n][0]);
	else
		cout << min(house[n][0], house[n][1]);
    return (0);
}
profile
정통과 / 정처기 & 정통기 / 42seoul 7기 Cardet / 임베디드 SW 개발자

0개의 댓글