Agorithm/백준 알고리즘
백준 알고리즘 10819번 차이를 최대로(python)
kimjinho1
2021. 3. 23. 19:25
728x90
반응형
브루트포스 알고리즘 & 백트래킹 문제이다.
def dfs(depth):
if depth == N:
res.append(sum(abs(li[i+1]-li[i]) for i in range(N-1)))
return ;
for i in range(N):
if check[i]:
continue
li.append(nums[i])
check[i] = 1
dfs(depth+1)
li.pop()
check[i] = 0
N = int(input())
nums = list(map(int, input().split()))
li, res = [], []
check = [0]*N
dfs(0)
print(max(res))
728x90
반응형