-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1149.cpp
53 lines (39 loc) · 890 Bytes
/
1149.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 1000
int notArr[2] = {0,};
void notMe(int rgb){
int num = 0;
for(int i=0; i<2; i++){
if(num == rgb) num++;
notArr[i] = num++;
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int arr[MAX][3] = {0,};
int dp[MAX][3] = {0,};
int n;
int res = 1000 * MAX ;
cin >> n;
for(int i=0; i<n; i++){
for(int j=0; j<3; j++){
cin >> arr[i][j];
}
}
dp[0][0] = arr[0][0];
dp[0][1] = arr[0][1];
dp[0][2] = arr[0][2];
for(int i=1; i<n; i++){
for(int j=0; j<3; j++){
notMe(j);
dp[i][j] = arr[i][j] + min(dp[i-1][notArr[0]],dp[i-1][notArr[1]]);
}
}
for(int i=0; i<3; i++){
res = min(res, dp[n-1][i]);
}
cout << res;
return 0;
}