itertools를 이용해 간단히 풀어보자
from itertools import permutations
N, M = map(int, input().split())
P = permutations(range(1, N + 1), M) # iter(tuple)
for i in P:
print(" ".join(map(str, i))) # tuple -> str
'개발 > Algorithm' 카테고리의 다른 글
[Python] 백준 14720번 우유 축제 (0) | 2021.11.15 |
---|---|
[Python] 백준 15650번 N과 M (2) (0) | 2021.11.15 |
[Python] 백준 1260번 DFS와 BFS (0) | 2021.11.12 |
[Python] 백준 10814번 나이순 정렬 (0) | 2021.11.11 |
[Python] 백준 1181번 단어 정렬 (0) | 2021.11.10 |
댓글