15649 문제를 통해 백트래킹을 이해한 덕분에 중복만 허용하지 않도록 바꾸면 되어서 바로 풀 수 있었다.
import sys, itertools
input = sys.stdin.readline
N, M = map(int, input().split())
lst = [i+1 for i in range(N)]
nCr = itertools.combinations(lst, M)
for i in nCr:
print(*i)
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
lst = []
def backtracking(i=1):
if len(lst) == M:
print(*lst)
return
for j in range(i, N+1):
if j not in lst:
lst.append(j)
backtracking(j+1)
lst.pop()
backtracking()
