문제
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];
house[0][1] = color[0][1];
house[0][2] = color[0][2];
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);
}