N 및 M1 문제와 거의 동일합니다.
https://khanwol.9
bf(m)이 출력될 때 나타나는 결과에서 오름차순이 아닌 것은 제외된다.
import sys
def bf(m):
global n
if m == 1:
return list(range(1, n+1))
result = ()
for i in bf(m-1):
copy_n_list = list(range(1, n+1))
if type(i) == int:
i = (i)
if type(i) == list:
copy_n_list = list(set(copy_n_list) - set(i))
copy_n_list.sort()
for j in copy_n_list:
append_list = i.copy()
append_list.append(j)
sort_list = append_list(:)
sort_list.sort(reverse=False)
if sort_list == append_list:
result.append(append_list)
return result
n, m = map(int, sys.stdin.readline().strip().split(' '))
if m == 1:
strs = list(map(str, bf(m)))
print('\n'.join(strs))
else:
strs = bf(m)
for i in strs:
i = list(map(str, i))
print(' '.join(i))
![[python] 백준 18352 특정 [python] 백준 18352 특정](https://place.best-news.co.kr/wp-content/plugins/contextual-related-posts/default.png)