알고리즘 분류)
백트래킹 입문 문제로 나와있는 것이다
1부터 N까지 자연수 중 M개를 중복없이 고르면 된다 -> 6! / 3! = 6P3
# 재귀함수 이용
def dfs(end, max_depth,stack):
for i in range(1,end+1):
if i in stack:
continue
else:
stack.append(i)
if len(stack) == max_depth:
print(*stack)
else:
dfs(end,max_depth,stack)
stack.pop()
end, max_depth = map(int, input().split())
stack = []
dfs(end,max_depth,stack)
# permutations 사용
from itertools import permutations
array = list(map(str, range(1,9)))
N, M = map(int, input().split())
array = array[0:N]
result=list(map(' '.join, permutations(array, M)))
for i in result:
print(i)