Skip to content

Commit

Permalink
7/9 PS 연산자 끼워 넣기
Browse files Browse the repository at this point in the history
  • Loading branch information
ChoiEungi committed Jul 10, 2021
1 parent ada5633 commit f68d7da
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions choieungi/NewThisIsCT/13_19 연산자 끼워 넣기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys
from collections import deque

n = int(input())
data = list(map(int, input().split()))
add, sub, mal, div = map(int, input().split())

min_val = sys.maxsize
max_val = -sys.maxsize

def dfs(i, data, now):
global min_val, max_val, add, sub, mal, div

if i == n :
min_val = min(min_val, now)
max_val = max(max_val, now)

else:
if add > 0:
add -= 1
dfs(i+1, data, now + data[i])
add += 1

if sub > 0:
sub -= 1
dfs(i + 1, data, now - data[i])
sub += 1

if mal > 0:
mal -= 1
dfs(i + 1, data, now * data[i])
mal += 1

if div > 0:
div -= 1
dfs(i + 1, data, int(now / data[i]))
div += 1

dfs(1, data, data[0])

print(max_val)
print(min_val)

0 comments on commit f68d7da

Please sign in to comment.