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

유현민·2022년 4월 25일
0

알고리즘

목록 보기
137/253

이번에는 오름차순으로 구해야하기 때문에 dfs에 현재 수를 준다.

N, M = map(int, input().split())
a = []


def dfs(n):
    if len(a) == M:
        print(' '.join(map(str, a)))
        return
    for i in range(n, N + 1):
        if i not in a:
            a.append(i)
            dfs(i)
            a.pop()


dfs(1)
profile
smilegate megaport infra

0개의 댓글