문제풀이/백준(Boj) 문제풀이

[백준(Boj)][14단계] 15651.N과 M (3) (파이썬/Python)

얄루몬 2021. 9. 5. 23:14

n, m =  map(int,input().split())
result = []

def dfs():
    #append된 값들이 m값만큼 들어와 있다면 출력
    if len(result) == m:
        print(' '.join(map(str,result)))
        return

    for i in range(1, n+1):
        result.append(i)
        #가지치기 작업
        dfs()
        result.pop()

dfs()