Problem solving

백준 16198번 에너지 모으기 (Python 3)

storkbear 2022. 9. 1. 14:55

Baekjoon online judge 16198번 파이썬

 

링크

https://www.acmicpc.net/problem/16198

 

 


소스코드

import sys
from collections import deque
from itertools import permutations
input = sys.stdin.readline

n=int(input())
s=list(map(int,input().split()))


now_max=-1

def dfs(energy):
  global now_max
  if len(s)==2:
    now_max=max(now_max,energy)
    return

  for i in range(1,len(s)-1):
    temp=s[i-1]*s[i+1]
    save=s[i]
    del s[i]
    dfs(energy+temp)
    s.insert(i,save)

dfs(0)
print(now_max)