Hyunwoo's DATA
boj-15658 연산자 끼워넣기 본문
https://www.acmicpc.net/problem/15658
간단한 가지치기 재귀 문제였다.
계속 오답이 나길래 이유를 찾아보니
음수를 양수로 나눌 때는 C++14의 기준을 따른다. ->int(n/m)으로 풀어야만 했다.
N = int(input())
S= list(map(int,input().split()))
OP = list(map(int,input().split()))
mn,mx=1000000000,-10000000
def solve(cnt,sum):
global mn,mx
if cnt==N-1:
mx=max(sum,mx)
mn=min(sum,mn)
return
for i in range(4):
if OP[i]!=0:
OP[i]-=1
if i==0:
tmp=sum+S[cnt+1]
solve(cnt+1,tmp)
OP[i]+=1
if i==1:
tmp=sum-S[cnt+1]
solve(cnt+1,tmp)
OP[i]+=1
if i==2:
tmp=sum*S[cnt+1]
solve(cnt+1,tmp)
OP[i]+=1
if i==3:
tmp=int(sum/S[cnt+1])
solve(cnt+1,tmp)
OP[i]+=1
solve(0,S[0])
print(mx)
print(mn)
'알고리즘 > 백준' 카테고리의 다른 글
boj-16198 에너지모으기 (0) | 2021.09.26 |
---|---|
boj -14225 부분수열의 합 (0) | 2021.09.25 |
boj- 1339 단어수학 (0) | 2021.09.25 |
boj-14889 스타트와 링크 (0) | 2021.09.23 |
boj-14501 퇴사 (0) | 2021.09.23 |