๋ฐฑ์ค 15649๋ฒ N๊ณผ M (1) https://www.acmicpc.net/problem/15649 ์ฝ๋ ์ค๋ช itertools ์ permutations ํจ์๋ฅผ ์ฌ์ฉํด์ ๊ตฌํ๋ฉด ํธ๋ฆฌํ๊ฒ ๋ต์ ๊ตฌํ ์ ์๋ค. -> ํ์ด์ฌ์ ์ข์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ ๊ณตํ๋ฏ๋ก ์ ์ฉํ๊ฒ ์ฌ์ฉํ๋ฉด ์ข๋ค. ์ถ๋ ฅํ ๋ ์ ์ถ๋ ฅ์์์ ๋ง๊ฒ ๋ ์ถ๋ ฅํด์ผ ํ๋ค. -> ์ฃผ์! ๋ฐ๋ก r์ ์ถ๋ ฅํ๋ฉด ํํ๋ก ์ถ๋ ฅ๋ ์ ์๋ค. itertools.permutations(iterable, r=None) ํจ์๋ iterable ์์์ ๊ธธ์ด r์ ํด๋นํ๋ ์์ด์ ๋ฆฌํดํ๋ ํจ์์ด๋ค. ์์ค์ฝ๋ ๋ฉ๋ชจ๋ฆฌ : 34952 KB ์๊ฐ : 252 ms from itertools import permutations n, m = tuple(map(int, input().split())) lst = [i for i in range(1, n+1)] result = list(permutations(lst, m)) for r in result: for e in r: print(e, end=" ") print()