728x90
반응형
기본적인 백트래킹 문제이다.
def dfs(depth):
if depth == M:
print(*li)
return ;
for i in range(N):
if check[i]:
continue
li.append(nums[i])
check[i] = 1
dfs(depth+1)
li.pop()
for j in range(i+1, N):
check[j] = 0
N, M = map(int, input().split())
nums = sorted(map(int, input().split()))
li = []
check = [0]*N
dfs(0)
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 15657번 N과 M (8)(python) (0) | 2021.03.24 |
---|---|
백준 알고리즘 15656번 N과 M (7)(python) (0) | 2021.03.24 |
백준 알고리즘 10819번 차이를 최대로(python) (0) | 2021.03.23 |
백준 알고리즘 1182번 부분수열의 합(python) (0) | 2021.03.23 |
백준 알고리즘 5636번 소수 부분 문자열(python) (0) | 2021.03.23 |