-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1149.cpp
More file actions
46 lines (37 loc) · 724 Bytes
/
1149.cpp
File metadata and controls
46 lines (37 loc) · 724 Bytes
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define INF 999999999
using namespace std;
int n;
int arr[1000][3];
int dp[1000][3];
void sol(int m, int col) {
if (m == n - 1) {
return;
}
for (int i = 0; i < 3; i++) {
if (i == col) continue;
if (dp[m][col] + arr[m + 1][i] < dp[m + 1][i]) {
dp[m + 1][i] = dp[m][col] + arr[m + 1][i];
sol(m + 1, i);
}
}
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> arr[i][j];
dp[i][j] = INF;
}
}
dp[0][0] = arr[0][0];
dp[0][1] = arr[0][1];
dp[0][2] = arr[0][2];
for (int i = 0; i < 3; i++) {
sol(0, i);
}
cout << min({ dp[n - 1][0], dp[n - 1][1], dp[n - 1][2] });
}