Skip to content

Commit 806d85a

Browse files
committed
[BOJ] 연산자 끼워넣기 / 실버1 / 40분
https://www.acmicpc.net/problem/14888
1 parent 30273e9 commit 806d85a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
def dfs(level, total, plus, minus, mul, div):
3+
global max_result
4+
global min_result
5+
global n
6+
7+
#종료 조건
8+
if level == n:
9+
max_result = max(total, max_result)
10+
min_result = min(total, min_result)
11+
12+
if plus != 0:
13+
dfs(level + 1, total + nums[level], plus - 1, minus, mul, div)
14+
if minus != 0:
15+
dfs(level + 1, total - nums[level], plus, minus - 1, mul, div)
16+
if mul != 0:
17+
dfs(level + 1, total * nums[level], plus, minus, mul - 1, div)
18+
if div != 0:
19+
dfs(level + 1, int(total / nums[level]), plus, minus, mul, div - 1)
20+
21+
22+
n = int(input())
23+
nums = list(map(int, input().split()))
24+
op = list(map(int, input().split()))
25+
26+
max_result = -int(1e9)
27+
min_result = int(1e9)
28+
dfs(1, nums[0], op[0], op[1], op[2], op[3])
29+
30+
print(max_result)
31+
print(min_result)

0 commit comments

Comments
 (0)