[백준 완전탐색] 차이를 최대로(python)

이진규·2022년 8월 23일
1

백준(PYTHON)

목록 보기
82/115

문제

https://www.acmicpc.net/problem/10819

나의 코드

"""

"""

from itertools import permutations
from sys import stdin
input = stdin.readline

n = int(input())
num_list = list(map(int, input().split()))
num_list = list(permutations(num_list, n)) # 모든 순열의 리스트를 구하고
answer = 0

for num in num_list:
    tmp = 0
    for i in range(len(num)-1): # 반복문을 돌며 최댓값을 갱신한다.
        tmp += abs(num[i] - num[i+1])
    answer = max(answer, tmp)

print(answer)

    

설명

순열 라이브러리 쓰고 반복문 돌리면 쉽게 풀 수 있는 문제

참고 자료

profile
항상 궁금해하고 공부하고 기록하자.

0개의 댓글