-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmin_ops.cpp
More file actions
62 lines (48 loc) · 1.26 KB
/
min_ops.cpp
File metadata and controls
62 lines (48 loc) · 1.26 KB
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
54
55
56
57
58
59
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iostream>
#include <map>
using namespace std;
int dp[110][1<<3];
int min_operations(vector <int> red, vector <int> green, vector <int> blue) {
int n = (int)red.size(), i, j;
for (i = 0; i <= n; i++) {
for (j = 0; j < 8; j++) {
dp[i][j] = 1<<30;
}
}
dp[0][0] = 0;
for (i = 0; i < n; i++){
for (j = 0; j < 8; j++){
dp[i + 1][j | 1] = min(dp[i + 1][j | 1], dp[i][j] + green[i] + blue[i]);
dp[i + 1][j | 2] = min(dp[i + 1][j | 2], dp[i][j] + red[i] + blue[i]);
dp[i + 1][j | 4] = min(dp[i + 1][j | 4], dp[i][j] + red[i] + green[i]);
}
}
j = 0;
for (i = 0; i < n; i++){
if (green[i]) j |= 2;
if (red[i]) j |= 1;
if (blue[i]) j |= 4;
}
if (dp[n][j] >= (1<<30))
dp[n][j] = -1;
return dp[n][j];
}
int main() {
int n, r, g, b;
cin >> n;
vector<int> red, blue, green;
for(int i = 0; i < n; i++){
cin >> r >> g >> b;
red.push_back(r);
green.push_back(g);
blue.push_back(b);
}
cout << min_operations(red, green, blue) << "\n";
return 0;
}