https://www.acmicpc.net/problem/15649
15649๋ฒ: N๊ณผ M (1)
ํ ์ค์ ํ๋์ฉ ๋ฌธ์ ์ ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์์ด์ ์ถ๋ ฅํ๋ค. ์ค๋ณต๋๋ ์์ด์ ์ฌ๋ฌ ๋ฒ ์ถ๋ ฅํ๋ฉด ์๋๋ฉฐ, ๊ฐ ์์ด์ ๊ณต๋ฐฑ์ผ๋ก ๊ตฌ๋ถํด์ ์ถ๋ ฅํด์ผ ํ๋ค. ์์ด์ ์ฌ์ ์์ผ๋ก ์ฆ๊ฐํ๋ ์์๋ก ์ถ๋ ฅํด
www.acmicpc.net
from itertools import permutations
n, m = map( int, input().split() )
arr = list( permutations( range(1, n+1) , m) )
for i in arr:
for j in i:
print(j,"", end='')
print()
๋ฆฌ์คํธ์ ์กฐํฉ์ ๊ด๋ จ๋๊ฑด itertools ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ฉด ํธํ๋ค.
์ฐธ๊ณ :
https://ourcstory.tistory.com/414
ํ์ด์ฌ(Python) ๋ฆฌ์คํธ ๋ชจ๋ ์กฐํฉ ๊ตฌํ๊ธฐ (combination vs permutations vs product)
ํ์ด์ฌ (Python)์์ ๋ฆฌ์คํธ์ ์๋ ๊ฐ๋ค์ ๋ชจ๋ ์กฐํฉ์ ๊ตฌํ๊ธฐ ํ์ด์ฌ์์ ๋ฆฌ์คํธ์ ์๋ ๊ฐ๋ค์ ๋ชจ๋ ์กฐํฉ์ ๊ตฌํ๊ธฐ ์ํด์๋ ์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์๋ค. ํ์ด์ฌ ๊ธฐ๋ณธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ธ itertools์ ์ฌ์ฉ
ourcstory.tistory.com
permutation: ์์ด
combination: ์กฐํฉ
'๐๊ณต๋ถ > ์ฝ๋ฉํ ์คํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค - ์์ ๊ตฌํ๊ธฐ, ํ์ด์ฌ (0) | 2021.12.06 |
---|---|
๋ฐฑ์ค - ์์ธ์๋ถํด, ํ์ด์ฌ (0) | 2021.12.05 |
๋ฐฑ์ค - ๋ค์ง๊ธฐ, ํ์ด์ฌ (0) | 2021.12.05 |
๋ฐฑ์ค - ์ฝ๊ฒ ํธ๋ ๋ฌธ์ , ํ์ด์ฌ (0) | 2021.12.05 |
๋ฐฑ์ค - ๋ฒ ์คํธ์ ๋ฌ, ํ์ด์ฌ (0) | 2021.12.05 |