문제#


#include <bits/stdc++.h>

using namespace std;

#define R 0
#define G 1
#define B 2

int cost[1002][3];
int dp[1002][3];
int n;

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

    cin >> n;

    for (int i = 1; i <= n; i++)
    	cin >> cost[i][R] >> cost[i][G] >> cost[i][B];

    dp[1][R] = cost[1][R]; dp[1][G] = cost[1][G]; dp[1][B] = cost[1][B];

    for (int i = 2; i <= n; i++) {
    	dp[i][R] = min(dp[i - 1][G], dp[i - 1][B]) + cost[i][R];
    	dp[i][G] = min(dp[i - 1][R], dp[i - 1][B]) + cost[i][G];
    	dp[i][B] = min(dp[i - 1][R], dp[i - 1][G]) + cost[i][B];
    }

    cout << min(dp[n][R], min(dp[n][G], dp[n][B])) << endl;

}
🗪 댓글