BOJ - 14888 - 연산자 끼워넣기
Updated:
retMax = -1e9
retMin = 1e9
def DFS(number, idx, T, add, sub, mul, div, value):
global retMax, retMin
if idx == T:
retMax = max(retMax, value)
retMin = min(retMin, value)
return
if add:
DFS(number, idx + 1, T, add - 1, sub, mul, div, value + number[idx])
if sub:
DFS(number, idx + 1, T, add, sub - 1, mul, div, value - number[idx])
if div:
DFS(number, idx + 1, T, add, sub, mul, div - 1, int(value / number[idx]))
if mul:
DFS(number, idx + 1, T, add, sub, mul - 1, div, value * number[idx])
def solution():
T = int(input())
number = list(map(int, input().split()))
add, sub, mul, div = map(int, input().split())
DFS(number, 1, T, add, sub, mul, div, number[0])
print(retMax)
print(retMin)
solution()
https://www.acmicpc.net/problem/14888
Leave a comment