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

유현민·2022년 4월 25일
0

알고리즘

목록 보기
136/253

백트래킹을 이용해서 푸는 문제이다.
재귀를 사용

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


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


dfs()
profile
smilegate megaport infra

0개의 댓글