웹찢남

[백준 15654 N과 M (5) 문제] PYTHON 본문

백준 Algorithm

[백준 15654 N과 M (5) 문제] PYTHON

harry595 2021. 8. 12. 22:29

이전 문제들과 달리 둘째줄에 숫자 배열이 주어졌다.

먼저 오름차순으로 출력하기 위해 sort를 한 후

이전과 같이 코딩을 하되 result 에는 i가 아닌 C[i]가 들어가게 한다. 

A, B = map(int, input().split())
C = list(map(int, input().split()))
C.sort()
result = []
visit = [False]*A


def backtracking(depth, A, B):
    if depth == B:
        print(' '.join(map(str, result)))
        return
    for i in range(A):
        if visit[i] == True:
            continue
        visit[i] = True
        result.append(C[i])
        backtracking(depth+1, A, B)
        result.pop()
        visit[i] = False


backtracking(0, A, B)
Comments