-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10819.py
45 lines (34 loc) · 894 Bytes
/
10819.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 차이를 최대로
n = int(input())
in_list = list(map(int, input().split()))
visited = [False]*n
answer = 0
def solution(li):
global answer
if len(li) == n:
total = 0
for i in range(n-1):
total += abs(li[i] - li[i+1])
answer = max(answer, total)
return
for i in range(n):
if not visited[i]:
visited[i] = True
li.append(in_list[i])
solution(li)
visited[i] = False
li.pop()
solution([])
print(answer)
# 순열 사용해보기
# import itertools
# n = int(input())
# in_list = list(map(int, input().split()))
# permutationList = itertools.permutations(in_list, n)
# answer = 0
# for mixedList in permutationList:
# total = 0
# for i in range(n-1):
# total += abs(mixedList[i]-mixedList[i+1])
# answer = max(answer, total)
# print(answer)