Files
Algorithm/250514/K개 중에 1개를 N번 뽑기/n-permutations-of-k-with-repetition.py

21 lines
416 B
Python

K, N = map(int, input().split())
# Please write your code here.
selected_nums = []
def print_permutation():
for num in selected_nums:
print(num, end = " ")
print()
def find_permutations(cnt):
if cnt == N:
print_permutation()
return
for i in range(1, K+1):
selected_nums.append(i)
find_permutations(cnt + 1)
selected_nums.pop()
find_permutations(0)