생성일: 2022년 2월 3일 오후 10:51
# 중복순열 구하기
import sys
#sys.stdin = open("input.txt", "rt")
def DFS(index):
global cnt
if index == m:
for x in res:
print(x, end=' ')
print()
cnt += 1
return
else:
for i in range(1,n+1):
res[index] = i
DFS(index+1)
if __name__ == "__main__":
n, m = map(int, input().split())
res = [0] * m
cnt = 0
DFS(0)
print(cnt)
⇒ 요약
중복 순열의 경우의 수를 담은 res 리스트 관점에서 index를 1씩 증가시키면서 n개의 수를 각 칸에 담은 경우의 수를 만들고 다음 인덱스로 넘어간다.