N, M = map(int, input().split())
num_list = [i + 1 for i in range(N)]
check_list = [False] * N
arr = []
def dfs(cnt):
if(cnt == M):
print(*arr)
return
for i in range(0, N):
if(check_list[i]):
continue
check_list[i] = True
arr.append(num_list[i])
dfs(cnt + 1)
arr.pop()
# 이 부분이 순열하고의 차이점이다.
# 큰 나무에서 전에 봤던 것만
# 닫아주면 된다.
for j in range(i + 1, N):
check_list[j] = False
dfs(0)
https://hwiyong.tistory.com/300?category=844316
(순열)
백준 15649번(python)
N, M = map(int, input().split()) num_list = [i + 1 for i in range(N)] check_list = [False] * N arr = [] def dfs(cnt): # 주어진 개수만큼 채워지면 출력한다 if(cnt == M): print(*arr) return for i in r..
hwiyong.tistory.com
'# 코딩 문제 관련 > 파이썬' 카테고리의 다른 글
백준 15652번(python) (0) | 2019.12.31 |
---|---|
백준 15651번(python) (6) | 2019.12.31 |
백준 15649번(python) (1) | 2019.12.31 |
백준 1912번(python) (0) | 2019.08.20 |
백준 9251번(python) (0) | 2019.08.20 |