728x90
문제링크
https://www.acmicpc.net/problem/14888
코드
import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
op = list(map(int, input().split()))
maximum = -1e9
minimum = 1e9
def dfs(depth, total, plus, minus, multiply, divide) :
global maximum, minimum
if depth == n:
maximum = max(total, maximum)
minimum = min(total, minimum)
return
if plus:
dfs(depth +1, total + num[depth], plus - 1, minus, multiply, divide)
if minus:
dfs(depth +1, total - num[depth], plus, minus - 1, multiply, divide)
if multiply:
dfs(depth +1, total * num[depth], plus, minus, multiply - 1, divide)
if divide:
dfs(depth +1, int(total / num[depth]), plus, minus, multiply, divide - 1)
dfs(1, num[0], op[0], op[1], op[2], op[3])
print(maximum)
print(minimum)
728x90
'코딩테스트' 카테고리의 다른 글
BFS&DFS_심화21) 인구이동 _ python (0) | 2023.09.25 |
---|---|
BFS&DFS_심화20) 감시 피하기 _ python (0) | 2023.09.25 |
BFS&DFS_심화18) 괄호변환 _ python (0) | 2023.09.25 |
BFS&DFS_심화17) 경쟁적 전염 _ python (0) | 2023.09.25 |
BFS&DFS_심화16) 연구소 _ python (0) | 2023.09.25 |