forked from b-chae/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14888.cpp
More file actions
52 lines (40 loc) · 1.01 KB
/
Copy path14888.cpp
File metadata and controls
52 lines (40 loc) · 1.01 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
#include <iostream>
using namespace std;
int T;
int num[11];
int oper[4]; // + - * %
int Amax = -1000000000;
int Amin = 1000000000;
void solve(int idx, int currentNum, int oper0, int oper1, int oper2, int oper3){
if(idx == T){
if(currentNum > Amax) Amax = currentNum;
if(currentNum < Amin) Amin = currentNum;
return;
}
if(oper0 < oper[0]){
solve(idx+1, currentNum+num[idx], oper0+1, oper1, oper2, oper3);
}
if(oper1 < oper[1]){
solve(idx+1, currentNum-num[idx], oper0, oper1+1, oper2, oper3);
}
if(oper2 < oper[2]){
solve(idx+1, currentNum*num[idx], oper0, oper1, oper2+1, oper3);
}
if(oper3 < oper[3]){
solve(idx+1, currentNum/num[idx], oper0, oper1, oper2, oper3+1);
}
}
int main()
{
cin >> T;
int t;
for(t=0; t<T; t++){
cin >> num[t];
}
for(t=0; t<4; t++){
cin >> oper[t];
}
solve(1, num[0], 0, 0, 0, 0);
cout << Amax << "\n" << Amin;
return 0;
}