๋ฐฑ์ค - N๊ณผ M (1), ํ์ด์ฌ
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: ์กฐํฉ