#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;

    int dp[1000][3];
    for (int i = 0; i < n; i++) {
        int r, g, b;
        cin >> r >> g >> b;

        if (i == 0) {
            dp[i][0] = r;
            dp[i][1] = g;
            dp[i][2] = b;
        }
        else{
            dp[i][0] = min(dp[i - 1][2], dp[i - 1][1]) + r;
        dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) + g;
        dp[i][2] = min(dp[i - 1][1], dp[i - 1][0]) + b;
        }
        
    }

    cout << min(min(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << '\n';

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: