본문 바로가기
알고리즘/DP

1149 RGB거리

by tryotto 2019. 2. 9.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <algorithm>
 
using namespace std;
int a[1001][4= { 0 };
int dp[1001][4= { 0 };
 
int main() {
    int n;
    scanf("%d"&n);
    getchar();
 
    for (int i = 1; i <= n; i++) {
        scanf("%d %d %d"&a[i][1], &a[i][2], &a[i][3]);
    }
 
    for (int i = 1; i <= n; i++) {
        dp[i][1= min(dp[i - 1][2], dp[i - 1][3]) + a[i][1];
        dp[i][2= min(dp[i - 1][1], dp[i - 1][3]) + a[i][2];
        dp[i][3= min(dp[i - 1][2], dp[i - 1][1]) + a[i][3];
    }
 
    int small = dp[n][1];
    small = min(small, dp[n][2]);
    small = min(small, dp[n][3]);
 
    printf("%d", small);
}
cs


'알고리즘 > DP' 카테고리의 다른 글

부분합 더블릿  (0) 2019.02.09
9251 LCS  (0) 2019.02.09
1463 1로 만들기  (0) 2019.02.08
2600 구슬게임  (0) 2019.02.08
01knapsack 더블릿 (복습 필요)  (0) 2019.02.08