덧셈, 뺄셈, 곱셈
연산자 간 우선 순위 무시, 앞에서부터 차례대로 연산
⇒ 가능한 식의 최솟값, 최댓값?
def dfs(depth, total, plus, sub, multi):
global MIN, MAX
if depth == n:
MIN = min(MIN, total)
MAX = max(MAX, total)
if plus:
dfs(depth + 1, total + num[depth], plus - 1, sub, multi)
if sub:
dfs(depth + 1, total - num[depth], plus, sub - 1, multi)
if multi:
dfs(depth + 1, total * num[depth], plus, sub, multi - 1)
n = int(input())
num = list(map(int, input().split()))
plus, sub, multi = map(int, input().split())
MIN, MAX = float("INF"), -float("INF")
dfs(1, num[0], plus, sub, multi)
print(MIN, MAX)
정답 코드가 아주 예술적이고 예쁘다… :)
언젠가 저런 코드를 내 손으로 작성할 수 있기를,,,ㅠ_ㅠ