-
Notifications
You must be signed in to change notification settings - Fork 0
/
14888_연산자끼워넣기.cpp
72 lines (52 loc) · 975 Bytes
/
14888_연산자끼워넣기.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//14888
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> v;
int arr[12];
int calc[4] = { 0 };
int N;
int calcNum;
int maxNum=-1000000000, minNum=1000000000;
void setCalcNum(int result, int n) {
if (n == N) {
maxNum = max(maxNum, result);
minNum = min(minNum, result);
return;
}
for (int i = 0; i < 4; i++) {
if (calc[i] > 0) {
calc[i]--;
if (i == 0) {
setCalcNum(result + arr[n], n + 1);
}
if (i == 1)
{
setCalcNum(result - arr[n], n + 1);
}
if (i == 2) {
setCalcNum(result * arr[n], n+1);
}
if (i == 3) {
setCalcNum(result / arr[n], n+1);
}
calc[i]++;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
for (int i = 0; i < 4; i++) {
cin >> calc[i];
}
setCalcNum(arr[0],1);
cout << maxNum << "\n" << minNum;
return 0;
}