Agorithm/백준 알고리즘
백준 알고리즘 15665번 N과 M (11)(python)
kimjinho1
2021. 3. 24. 22:21
728x90
반응형
기본적인 백트래킹 문제이다. 15663번 N과 M (9)와 비슷한 문제이다.
def dfs(depth):
if depth == M:
s = ' '.join(map(str, li))
if s not in d:
d[s] = 1
print(s)
return ;
for i in range(N):
li.append(nums[i])
dfs(depth+1)
li.pop()
N, M = map(int, input().split())
nums = sorted(map(int, input().split()))
d = {}; li = []
dfs(0)
728x90
반응형