168. N과 M(9)

아현·2021년 7월 9일
0

Algorithm

목록 보기
172/400
post-custom-banner

백준




1. Python







n, m = map(int, input().split())
data = list(map(int, input().split()))

data.sort()
visited = [False] * n
out = []

def recur(k):
    if k == m:
        print(' '.join(map(str, out)))
        return
    overlap = 0
    for i in range(n):
        if not visited[i] and overlap != data[i]:
            visited[i] = True
            out.append(data[i])
            overlap = data[i]
            recur(k+1)
            visited[i] = False
            out.pop()

recur(0)



2. C++




profile
For the sake of someone who studies computer science
post-custom-banner

0개의 댓글