https://www.acmicpc.net/problem/10819
10819번: 차이를 최대로
첫째 줄에 N (3 ≤ N ≤ 8)이 주어진다. 둘째 줄에는 배열 A에 들어있는 정수가 주어진다. 배열에 들어있는 정수는 -100보다 크거나 같고, 100보다 작거나 같다.
www.acmicpc.net
📕 설명 📕
Brute-Force로 permutations python library로 list에서 모두 꺼내와서 접근하였다.
🧑🏻💻 나의 풀이 🧑🏻💻
from itertools import permutations
N = int(input())
N_list = list(map(int ,input().split()))
result = 0
for i in permutations(N_list):
total = 0
for j in range(1,N):
total += abs(i[j-1] - i[j])
if total > result:
result = total
print(result)
'Programming > Algorithm' 카테고리의 다른 글
[백준] #1547 공 python (0) | 2023.01.26 |
---|---|
[백준] #1371 가장 많은 글자 python (0) | 2023.01.25 |
[백준] #2501 약수 구하기 python (0) | 2023.01.23 |
[백준] #2476 주사위 게임 python (0) | 2023.01.22 |
[백준] #2455 지능형 기차 python (0) | 2023.01.21 |