λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
πŸƒ algorithm/boj

BOJ 10819 - 차이λ₯Ό μ΅œλŒ€λ‘œ

by HandHand 2021. 3. 18.

문제

λ°±μ€€ 온라인 저지 - 10819번

풀이 κ³Όμ •

μˆ˜μ—΄ 을 μƒμ„±ν•΄μ„œ λͺ¨λ“  κ°€λŠ₯ν•œ 경우의 μˆ˜λ“€μ„ λ§Œλ“€μ–΄λ³΄λŠ” μ™„μ „ 탐색 λ¬Έμ œμž…λ‹ˆλ‹€.
이후에 λ¬Έμ œμ—μ„œ μ œμ‹œλœ μˆ˜μ‹μ„ μ΄μš©ν•΄μ„œ 값을 κ³„μ‚°ν•˜κ³  이 쀑 μ΅œλŒ€κ°’μ„ λ‹΅μœΌλ‘œ λ°˜ν™˜ν•˜λ©΄ λ©λ‹ˆλ‹€.

μ½”λ“œ


import sys
from itertools import permutations


def solution():
    max_value = 0

    for perm in permutations(numbers):
        acc = 0
        for i in range(N - 1):
            acc += abs(perm[i] - perm[i + 1])
        max_value = max(max_value, acc)

    return max_value


if __name__ == '__main__':
    N = int(input())
    numbers = list(map(int, sys.stdin.readline().split()))

    answer = solution()
    print(answer)
λ°˜μ‘ν˜•

'πŸƒ algorithm > boj' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

BOJ 1260 - DFS와 BFS  (0) 2021.03.18
BOJ 6550 - λΆ€λΆ„ λ¬Έμžμ—΄  (0) 2021.03.18
BOJ 15240 - Paint bucket  (0) 2021.03.18
BOJ 1449 - 수리곡 ν•­μŠΉ  (0) 2021.03.18
BOJ 2805 - λ‚˜λ¬΄ 자λ₯΄κΈ°  (0) 2021.03.18

πŸ’¬ λŒ“κΈ€