
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)
이렇게 풀어야 하나 보다.
| [파이썬/python] 백준 15652번 : N과 M (4) (🥈3) (0) | 2023.06.11 |
|---|---|
| [파이썬/python] 백준 15651번 : N과 M (3) (🥈3) (0) | 2023.06.11 |
| [파이썬/python] 백준 15649번 : N과 M (1) (🥈3) (0) | 2023.06.11 |
| [파이썬/python] 백준 1436번 : 영화감독 숌 (🥈5) (0) | 2023.06.11 |
| [파이썬/python] 백준 28224번 : Final Price (🥉4) (0) | 2023.06.10 |