Baekjoon/백트래킹

[백준] 15656 N과 M (7) (실버3) / 백트래킹

hellosonic 2023. 4. 14. 10:36

문제요약

나의 코드 및 설명

def dfs(count):
    if count == m:
        print(" ".join(map(str, ans)))
        return
    if count == n:
        return
    for i in range(n):
        ans.append(num_list[i])
        dfs(count+1)
        ans.pop()

n, m = map(int, input().split())
num_list = list(map(int, input().split()))
num_list.sort()
ans = []

dfs(0)