알고리즘/백준
[백준] 15657번(python 파이썬)
G_Gi
2021. 1. 10. 19:35
SMALL
입력으로 n개의 숫자를 임의로 받는다.
이를 list형태로 저장하고 숫자가 작은 것부터 탐색을 해야 하기 때문에 오름차순으로 정렬을 한다.
이전 방문 노드보다 같거나, 큰 숫자를 append한다.
( if depth == 0 or solve[depth - 1] <= my_list[i] )
반복문의 i를 solve 리스트에 append, pop 하는 것이 아닌 오름차순으로 정렬한 리스트의 i번째 값을 append, pop 한다.
n, m = map(int, input().split())
my_list = list(map(int, input().split()))
my_list.sort()
solve = []
def Dfs(depth):
if depth == m:
print(' '.join(map(str, solve)))
return
for i in range(n):
if depth == 0 or solve[depth - 1] <= my_list[i]:
solve.append(my_list[i])
Dfs(depth + 1)
solve.pop()
Dfs(0)
LIST