-
[๋ฐฑ์ค] 10819 ์ฐจ์ด๋ฅผ ์ต๋๋ก with PythonPS 2022. 1. 11. 17:53728x90๋ฐ์ํ
๐ BOJ 10819 ์ฐจ์ด๋ฅผ ์ต๋๋ก
๐ก ์กฐ๊ฑด
N๊ฐ์ ์ ์๋ก ์ด๋ฃจ์ด์ง ๋ฐฐ์ด A
N (3 โค N โค 8)
๋ฐฐ์ด์ ๋ค์ด์๋ ์ ์๋
-100๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๊ณ , 100๋ณด๋ค ์๊ฑฐ๋ ๊ฐ๋ค.
๋ค์ ์์ ์ต๋๊ฐ์ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑ.
|A[0] - A[1]| + |A[1] - A[2]| + ... + |A[N-2] - A[N-1]|
5. **๋ธ๋ฃจํธํฌ์ค ์๊ณ ๋ฆฌ์ฆ ์ ํ**์ ๋ฌธ์ ## ๐ฅ ์์ค ์ฝ๋
from sys import stdin
from itertools import permutationsn = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
res = -int(1e9)for arr2 in permutations(arr, n):
v = 0
for i in range(n-1):
v += abs(arr2[i] - arr2[i + 1])res = max(res, v)
print(res)
## ๐ ์์ ๋ฐ ์คํ๊ฒฐ๊ณผ #### ์์
6
20 1 15 8 4 10#### ์คํ๊ฒฐ๊ณผ
62
```
โจ๏ธ ๋ฌธ์ ํ์ด
์ต๋๊ฐ์ ์ ์ฅํ res ์ ์ ์์ฑ
itertools ์ permutaions ํจ์๋ก ๊ฐ๋ฅํ ์๋ฅผ ๋ชจ๋ ๊ณ์ฐํ์ฌ v์ ์ ์ฅํ๊ณ , res ๊ฐฑ์
๐พ ๋๋์
- ๋ฐฐ์ด์ ํฌ๊ธฐ๊ฐ ์ต๋ 8๊ฐ ๋ฐ์ ์๋๊ธฐ์ permutaions๋ฅผ ์ผ๋ค.
- ๋ง์ฝ ๋ฐฐ์ด์ ํฌ๊ธฐ๊ฐ ์ปธ๋ค๋ฉด?
๋ฐ์ํ'PS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 14502 ์ฐ๊ตฌ์ with Python (0) 2022.01.24 [๋ฐฑ์ค] 11504 ๋๋ ค ๋๋ ค ๋๋ฆผํ! with Python (0) 2022.01.11 [๋ฐฑ์ค] 9461 ํ๋๋ฐ ์์ด with Python (0) 2022.01.10 [๋ฐฑ์ค] 1535 ์๋ with Python (0) 2022.01.10 [๋ฐฑ์ค] 1063 ํน with Python (0) 2021.12.29