728x90
반응형

그냥 백트래킹 형식으로 쉽게 풀었다. 

def dfs(depth):
    if depth == k:
        s.add(''.join(map(str, li)))
        return ;
    for i in range(n):
        if check[i]:
            continue
        li.append(nums[i])
        check[i] = 1
        dfs(depth+1)
        li.pop()
        check[i] = 0
        
n, k = int(input()), int(input())
nums = [int(input()) for _ in range(n)]
li, s = [], set()
check = [0]*n
dfs(0)
print(len(s))
728x90
반응형

+ Recent posts