Algorithm/BackTracking
[Baekjoon 15665 / Python / 실버2] N과 M (11)
양선규
2024. 8. 10. 15:25
728x90
반응형

import sys
input = sys.stdin.readline
N, M = map(int, input().split())
numbers = list(map(int, input().split()))
numbers.sort()
result = [-1] * M
def backTracking(depth):
if depth == M:
print(' '.join(map(str, result)))
return
temp = 0
for i in range(N):
if temp != numbers[i]:
temp = numbers[i]
result[depth] = numbers[i]
backTracking(depth + 1)
backTracking(0)
이전 10번 문제에서 visited를 사용하지 않고, 비내림차순 조건문을 빼주면 된다.
이번 문제가 더 간단한데, 순서가 반대여야 하는 것 아닌가 싶다.
728x90
반응형