~์ค๋ฒ 2~
๋ฐฑํธ๋ํน(Backtracking) ์๊ณ ๋ฆฌ์ฆ์ ํ์ตํ๋ ๊ณผ์ ์์ ๋ง๋ ๋ฐฑ์ค ๋ฌธ์ !
https://www.acmicpc.net/problem/10819
[์ต์ข ์ฝ๋]
from itertools import permutations
n = int(input())
alist = list(map(int, input().split()))
maxN = 0
nPr = permutations(alist)
for p in nPr:
temp = 0
for i in range(n-1):
temp += abs(p[i] - p[i+1])
if temp > maxN:
maxN = temp
print(maxN)
'๐๋ฌธ์ ํ์ด > ๐งฉBaekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] ๋ฐฑ์ค 1463 1๋ก ๋ง๋ค๊ธฐ | DP (0) | 2023.05.15 |
---|---|
[Python] ๋ฐฑ์ค 9663 N-Queen | ์๊ฐ์ด๊ณผ (2) | 2023.04.18 |
[Python] ๋ฐฑ์ค 2089 -2์ง์ (0) | 2023.03.02 |
[Python] ๋ฐฑ์ค 1107 ๋ฆฌ๋ชจ์ปจ | EOFError | ๋ธ๋ฃจํธํฌ์ค ์๊ณ ๋ฆฌ์ฆ (0) | 2023.03.02 |
[Python] ๋ฐฑ์ค 16924 ์ญ์๊ฐ ์ฐพ๊ธฐ | ์์ ํ์ | ๋ธ๋ฃจํธํฌ์ค(Brute-force) (0) | 2023.03.01 |