#백준 10819
from itertools import permutations
N=int(input())
list_arr = list(map(int, input().split()))
answer=-1
for p in list(permutations(list_arr)):
sum=0
for j in range(N-1):
sum+=abs(p[j] -p[j+1])
if answer <sum:
answer= sum
print(answer)
▶ Brute-force : 무식하게 모든 경우의 수를 모두 생각해본다.
'파이썬 알고리즘 > 알고리즘 백준' 카테고리의 다른 글
K번째 수(2501번) (0) | 2022.10.29 |
---|