Algorithm (PS)
[백준] 10819 in Python 차이를 최대로
minjiwoo
2022. 2. 17. 22:49
728x90
permutations 를 써서 가능한 순열 조합들을 모두 확인해 보는 방법으로 풀었다.
https://www.acmicpc.net/problem/10819
10819번: 차이를 최대로
첫째 줄에 N (3 ≤ N ≤ 8)이 주어진다. 둘째 줄에는 배열 A에 들어있는 정수가 주어진다. 배열에 들어있는 정수는 -100보다 크거나 같고, 100보다 작거나 같다.
www.acmicpc.net
# 10819 차이를 최대로
from itertools import permutations
n = int(input())
array = list(map(int, input().split()))
result = 0
cases = permutations(array, n)
for case in cases:
temp = 0
for i in range(n-1):
temp += abs(case[i] - case[i+1])
if result < temp:
result = temp
print(result)
728x90