From dea0b75183f048c70cdf2671762562897cca6298 Mon Sep 17 00:00:00 2001 From: SSUM <116950962+ssum21@users.noreply.github.com> Date: Wed, 14 May 2025 20:51:34 +0900 Subject: [PATCH] =?UTF-8?q?Title:=20K=EA=B0=9C=20=EC=A4=91=EC=97=90=201?= =?UTF-8?q?=EA=B0=9C=EB=A5=BC=20N=EB=B2=88=20=EB=BD=91=EA=B8=B0,=20Time:?= =?UTF-8?q?=20218ms,=20Memory:=2027MB,=20Status:=20Passed=20-=20Codetree?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../n-permutations-of-k-with-repetition.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 250514/K개 중에 1개를 N번 뽑기/n-permutations-of-k-with-repetition.py diff --git a/250514/K개 중에 1개를 N번 뽑기/n-permutations-of-k-with-repetition.py b/250514/K개 중에 1개를 N번 뽑기/n-permutations-of-k-with-repetition.py new file mode 100644 index 0000000..2721557 --- /dev/null +++ b/250514/K개 중에 1개를 N번 뽑기/n-permutations-of-k-with-repetition.py @@ -0,0 +1,21 @@ +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) \ No newline at end of file