-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14888_연산자_끼워넣기.cpp
65 lines (55 loc) · 1.15 KB
/
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
#include <bits/stdc++.h>
#define SIZE 11
#define INF 1000000001
using namespace std;
int N;
int arr[SIZE];
int ops[4];
int answer[2] = {INF, -INF};
void solve(int cnt, int pvalue)
{
if (cnt == N)
{
answer[0] = min(answer[0], pvalue);
answer[1] = max(answer[1], pvalue);
return;
}
for (int i = 0; i < 4; i++)
{
if (ops[i] == 0)
continue;
int nvalue = pvalue;
switch (i)
{
case 0:
nvalue += arr[cnt];
break;
case 1:
nvalue -= arr[cnt];
break;
case 2:
nvalue *= arr[cnt];
break;
case 3:
nvalue /= arr[cnt];
break;
}
ops[i]--;
solve(cnt + 1, nvalue);
ops[i]++;
}
}
int main(void)
{
ios_base::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 >> ops[i];
solve(1, arr[0]);
cout << answer[1] << endl
<< answer[0] << endl;
return 0;
}