15650: N과 M (2)

ewillwin·2023년 4월 28일
0

Problem Solving (BOJ)

목록 보기
21/230

import sys

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

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

dfs(1)
  • 출력되는 수열이 오름차순이어야 하기 때문에, flag를 dfs()의 인수로 넘겨줘야함
profile
Software Engineer @ LG Electronics

0개의 댓글