-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_14888.cpp
More file actions
55 lines (46 loc) · 804 Bytes
/
BOJ_14888.cpp
File metadata and controls
55 lines (46 loc) · 804 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
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
int N;
int arr[12];
int op[4];
int max_res = INT_MIN;
int min_res = INT_MAX;
void DFS(int x, int res){
if (x == N - 1){
max_res = max(max_res, res);
min_res = min(min_res, res);
}
for (int i = 0; i < 4; i++){
if (op[i] > 0) {
op[i]--;
if (i == 0) {
DFS(x + 1, res + arr[x + 1]);
}
else if (i == 1) {
DFS(x + 1, res - arr[x + 1]);
}
else if (i == 2) {
DFS(x + 1, res * arr[x + 1]);
}
else if (i == 3) {
DFS(x + 1, res/ arr[x + 1]);
}
op[i]++;
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++){
cin >> arr[i];
}
for (int i = 0; i < 4; i++){
cin >> op[i];
}
DFS(0, arr[0]);
cout << max_res << '\n';
cout << min_res << '\n';
return 0;
}