๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ๐Ÿฃ: ๐’œ๐“๐‘”๐‘œ๐“‡๐’พ๐“‰๐’ฝ๐“‚/์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ํ’€์ด

BOJ1149 : RGB๊ฑฐ๋ฆฌ (Silver 1)

#include <iostream>
using namespace std;
int cost[1000][3];
long long costDP[1000][2];
void makeDP(int N)
{
    costDP[0][0] = cost[0][0];
    costDP[0][1] = cost[0][1];
    costDP[0][2] = cost[0][2];
    for (int i = 1; i < N; i++)
    {
        costDP[i][0] = min(costDP[i - 1][1], costDP[i - 1][2]) + cost[i][0];
        costDP[i][1] = min(costDP[i - 1][0], costDP[i - 1][2]) + cost[i][1];
        costDP[i][2] = min(costDP[i - 1][0], costDP[i - 1][1]) + cost[i][2];
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> cost[i][0] >> cost[i][1] >> cost[i][2];
    }
    makeDP(N);
    long long result =
        min(costDP[N - 1][0], costDP[N - 1][1]) > costDP[N - 1][2] ? costDP[N - 1][2] : min(costDP[N - 1][0], costDP[N - 1][1]);
    cout << result;
}