-
[10819] 차이를 최대로 (Python)[Python] 알고리즘/Silver 2022. 4. 12. 11:47
[문제]
https://www.acmicpc.net/problem/10819
알고리즘 분류는 브루트포스 알고리즘, 백트래킹 입니다.
저는 Python의 permutations (순열)을 사용하여 풀었습니다.
[코드]
import sys from itertools import permutations N = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) perm = list(permutations(A, N)) max = -1 for i in perm: res = 0 for j in range(N - 1): res += abs(i[j] - i[j + 1]) if max < res: max = res print(max)
'[Python] 알고리즘 > Silver' 카테고리의 다른 글
[1912] 연속합 (Python) (0) 2022.04.30 [9184] 신나는 함수 실행 (Python) (1) 2022.04.12 [1182] 부분수열의 합 (Python) (0) 2022.04.04 [6603] 로또 (Python) (0) 2022.04.04 [1535] 안녕 (Python) (0) 2022.03.21