최대 1 분 소요

사용 언어: Python3

문제

스크린샷 2023-05-04 오후 12 09 45

풀이

def DFS(L, S): # L: Level, S: Start
    global cnt
    if L == M:
        cnt += 1
        print(' '.join(map(str, res)))
    else:
        for i in range(S, N+1): # ✅ S부터 range 시작
            res[L] = i
            DFS(L+1, i+1) # ✅ S+1이 아니라 i+1 이다

N, M = map(int, input().split())

res = [0] * M
cnt = 0

DFS(0, 1)
print(cnt)

IMG_0435



💛 개인 공부 기록용 블로그입니다. 👻

맨 위로 이동하기