https://www.acmicpc.net/problem/1149
#include <iostream>
using namespace std;
int n;
const int MAX = 1000;
int cost[MAX][3];
// RGB거리
int solution(){
int color[MAX][3];
color[0][0] = cost[0][0];
color[0][1] = cost[0][1];
color[0][2] = cost[0][2];
for(int i=1;i<n;i++){
color[i][0] = min(color[i-1][1], color[i-1][2]) + cost[i][0];
color[i][1] = min(color[i-1][0], color[i-1][2]) + cost[i][1];
color[i][2] = min(color[i-1][0], color[i-1][1]) + cost[i][2];
}
return min(color[n-1][0],min(color[n-1][1], color[n-1][2]));
}
#include <stdio.h>
#include <algorithm>
using namespace std;
int n;
int r,g,b,R,G,B,x,y,z;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d%d",&r,&g,&b);
if(i==0) {R=r; G=g; B=b; continue;}
x=min(G,B)+r;
y=min(R,B)+g;
z=min(R,G)+b;
R=x; G=y; B=z;
}
int ans=min(R,min(G,B));
printf("%d",ans);
}