Skip to content

Commit 4598764

Browse files
authored
Create 5.py
1 parent 790a518 commit 4598764

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

13/5.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
n = int(input())
2+
# 연산을 수행하고자 하는 수 리스트
3+
data = list(map(int, input().split()))
4+
# 더하기, 빼기, 곱하기, 나누기 연산자 개수
5+
add, sub, mul, div = map(int, input().split())
6+
7+
min_value = 1e9
8+
max_value = -1e9
9+
10+
def dfs(i, now):
11+
global min_value, max_value, add, sub, mul, div
12+
if i == n:
13+
min_value = min(min_value, now)
14+
max_value = max(max_value, now)
15+
else:
16+
# 각 연산자에 대하여 DFS 수행
17+
if add > 0:
18+
add -= 1
19+
dfs(i + 1, now + data[i])
20+
add += 1
21+
if sub > 0:
22+
sub -= 1
23+
dfs(i + 1, now - data[i])
24+
sub += 1
25+
if mul > 0:
26+
mul -= 1
27+
dfs(i + 1, now * data[i])
28+
mul += 1
29+
if div > 0:
30+
div -= 1
31+
dfs(i + 1, int(now / data[i])) # 나눌 때는 나머지를 제거
32+
div += 1
33+
34+
dfs(1, data[0])
35+
print(max_value)
36+
print(min_value)

0 commit comments

Comments
 (0)