Skip to content

Commit 035af90

Browse files
committed
[BOJ] #15649.N과 M (1) / 실버3 / 30(O)
1 parent d6984de commit 035af90

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
N, M = map(int, input().split())
2+
visited = [False] * (N + 1) # 1부터 N까지 사용 여부
3+
result = []
4+
5+
def backtrack():
6+
if len(result) == M:
7+
print(' '.join(map(str, result)))
8+
return
9+
10+
for i in range(1, N + 1):
11+
if not visited[i]:
12+
visited[i] = True
13+
result.append(i)
14+
backtrack()
15+
result.pop() # 상태 복원
16+
visited[i] = False # 방문 초기화
17+
18+
backtrack()

0 commit comments

Comments
 (0)