/*#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
*/
/*#include<stdio.h>
int n;
int arr[100][100]= {};
int memo[100][100]= {};
int min(int a,int b)
{
return a>b?b:a;
}
int color(int value,int count)
{
int a,b;
if(value==0)
{
a=1;
b=2;
}
if(value==1)
{
a=0;
b=2;
}
if(value==2)
{
a=0;
b=1;
}
if(count==n-1)
{
return arr[count][value];
}
if(memo[count][value]!=0)
{
return memo[count][value];
}
return memo[value][count]=min(arr[count][value] + color(a, count+1), arr[count][value] + color(b, count+1));
}
int main()
{
scanf("%d",&n);
for(int i=0; i<n; i++)
{
for(int j=0; j<3; j++)
{
scanf("%d",&arr[i][j]);
}
}
printf("%d",min(min(color(0,0),color(1,0)),color(2,0)));
return 0;
}*/
#include<stdio.h>
int arr[20][20]={},memo[100][100]={},n,min=99999999,sum=0;
int color(int a)
{
for(int i=1;i<a+1;i++)
{
for(int j=1;j<4;j++)
{
if(memo[i-1][j-1]!=0)
{
min=memo[i-1][j-1];
}
if(a==i)
{
min=arr[a+1][j];
}
}
sum+=min;
}
return color(a-1)+color(a+1);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<n+1;i++)
{
for(int j=1;j<4;j++)
{
scanf("%d",&arr[i][j]);
}
}
printf("%d",color(n));
return 0;
}
풀어보세요:https://codeup.kr/problem.php?id=3501



