[백준] 1149 RGB거리
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n;
cin >> n;
vector<vector<int>> paint(n, vector<int>());
for (int i = 0; i < n; ++i) {
int r, g, b;
cin >> r >> g >> b;
paint[i].push_back(r);
paint[i].push_back(g);
paint[i].push_back(b);
}
vector<int> totalCost(3, 0);
for (int i = 0; i < n; ++i) {
vector<int> tmpCost(3, 0);
tmpCost[0] = min(totalCost[1], totalCost[2]) + paint[i][0];
tmpCost[1] = min(totalCost[0], totalCost[2]) + paint[i][1];
tmpCost[2] = min(totalCost[0], totalCost[1]) + paint[i][2];
totalCost[0] = tmpCost[0];
totalCost[1] = tmpCost[1];
totalCost[2] = tmpCost[2];
}
cout << min(min(totalCost[0], totalCost[1]), totalCost[2]);
return 0;
}