-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path49_boj_14888.py
More file actions
executable file
·42 lines (40 loc) · 944 Bytes
/
49_boj_14888.py
File metadata and controls
executable file
·42 lines (40 loc) · 944 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
n = int(input())
seq = list(map(int, input().split()))
a,b,c,d = map(int, input().split())
output = []
visited = [0]*(n-1)
oper = []
for _ in range(a) :
oper.append("+")
for _ in range(b) :
oper.append("-")
for _ in range(c) :
oper.append("*")
for _ in range(d) :
oper.append("/")
def dfs(cnt, calc) :
if cnt == n-1 :
output.append(calc)
return
cnt += 1
for i in range(n-1) :
if visited[i] == 1 :
continue
visited[i] = 1
buf = oper[i]
tmp = calc
if buf == "+" :
calc += seq[cnt]
elif buf == "-" :
calc -= seq[cnt]
elif buf == "*" :
calc *= seq[cnt]
elif buf == "/" :
calc = int(calc / seq[cnt])
dfs(cnt, calc)
visited[i] = 0
calc = tmp
dfs(0,seq[0])
output.sort()
print(output[len(output)-1])
print(output[0])