-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj14888
More file actions
45 lines (38 loc) · 871 Bytes
/
Copy pathboj14888
File metadata and controls
45 lines (38 loc) · 871 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
#include<iostream>
using namespace std;
int N;
int operands[11];
int operators[4];
int amin = 1000000001;
int amax = -1000000001;
void getanswer(int result, int idx) {
if (idx == N) {
if (result > amax)amax = result;
if (result < amin)amin = result;
return;
}
for (int i = 0; i < 4; i++) {
if (operators[i] > 0) {
operators[i]--;
if (i == 0)
getanswer(result + operands[idx], idx + 1);
else if (i == 1)
getanswer(result - operands[idx], idx + 1);
else if (i == 2)
getanswer(result * operands[idx], idx + 1);
else
getanswer(result / operands[idx], idx + 1);
operators[i]++;//연산자 복구
}
}
return;
}
int main(void) {
cin >> N;
for (int i = 0 ; i < N; i++) cin >> operands[i];
for (int j = 0; j < 4; j++) cin >> operators[j];
getanswer(operands[0], 1);
cout << amax << '\n';
cout << amin;
return 0;
}