[파이썬/python] 백준 15650번 : N과 M (2) (🥈3)

n,m = list(map(int,input().split()))
 
s = [0]
 
def dfs():
    if len(s)==m+1:
        print(' '.join(map(str,s[1:])))
        return
    
    for i in range(1,n+1):
        if i not in s and i > s[-1]:
            s.append(i)
            dfs()
            s.pop()
 
dfs()

나는 이렇게 풀었는데 정석 풀이는 아닌 것 같고..ㅋㅋ

 

 

n,m = list(map(int,input().split()))
 
s = []
 
def dfs(ss):
    if len(s)==m:
        print(' '.join(map(str,s)))
        return
    
    for i in range(ss,n+1):
        if i not in s:
            s.append(i)
            dfs(i+1)
            s.pop()
 
dfs(1)

이렇게 풀어야 하나 보다.

comment