문제 링크: https://www.acmicpc.net/problem/10819
백준 알고리즘 기초 2/2 520에서 4번째 - 10819번 차이를 최대로를 풀어보았다.
풀이: 브루트 포스 문제인 만큼 전부 구해보면 된다.
C++
Python
from itertools import permutations
n=int(input())
inp=list(map(int,input().split()))
per=list(permutations(inp,n))
res=-10000000
for i in per:
temp=0
for j in range(n-1):
temp+=abs(i[j]-i[j+1])
if temp>res: res=temp
print(res)
Java
'코테용 문제풀이 > 백준' 카테고리의 다른 글
로또 풀이 (0) | 2023.01.28 |
---|---|
외판원 순회 2 풀이 (0) | 2023.01.25 |
모든 순열 풀이 (0) | 2023.01.25 |
이전 순열 풀이 (0) | 2023.01.25 |
다음 순열 풀이 (0) | 2023.01.25 |