Skip to content

Commit 1fee687

Browse files
committed
[BOJ] N과 M / 실버3 / 20분
https://www.acmicpc.net/problem/15649
1 parent 4f5178c commit 1fee687

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def backtracking(cnt, arr):
2+
global answer, N, M
3+
if M == cnt:
4+
answer.append(arr[:]) # 결과를 복사해서 저장
5+
return
6+
7+
for i in range(1, N+1):
8+
if i not in arr: # 중복 방지
9+
arr.append(i)
10+
backtracking(cnt+1, arr)
11+
arr.pop() # 마지막 원소 제거로 백트래킹
12+
13+
N, M = map(int, input().split())
14+
15+
answer = []
16+
17+
backtracking(0, [])
18+
19+
# answer 리스트에서 하나씩 출력
20+
for ans in answer:
21+
print(" ".join(map(str, ans)))

0 commit comments

Comments
 (0)