from itertools import permutations를 활용하면
성능은 좀 그렇지만 쉽게 구현이 가능하다..
from itertools import permutations
lengthOfData = int(input())
dataList = list(map(int, input().split()))
ans = 0
for i in permutations(dataList):
tempVal = 0
for j in range(lengthOfData - 1):
tempVal += abs(i[j] - i[j + 1])
ans = max(ans, tempVal)
print(ans)
'Algorithm > Brute force' 카테고리의 다른 글
[백준] 14888번 연산자 끼워넣기 (0) | 2021.02.05 |
---|---|
[백준] 1182 부분수열의 합 (0) | 2021.02.04 |
[백준] 2309번 일곱 난쟁이 (0) | 2021.02.04 |
[백준] 2798 블랙잭 (0) | 2021.02.04 |
댓글