[알고리즘/백준] 15657: N과 M(8)(python)

유현민·2022년 4월 27일
0

알고리즘

목록 보기
144/253

백트래킹을 수행할 때 현재 숫자를 줘야한다.

def dfs(l):
    if len(q) == M:
        print(' '.join(map(str, q)))
        return

    for i in range(l, N):
        q.append(a[i])
        dfs(i)
        q.pop()


q = []
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dfs(0)
profile
smilegate megaport infra

0개의 댓글