BOJ - 10974 - 모든 순열

Updated:

import sys

def DFS(start, check, word, N, count):

    if count == N:
        print(" ".join(map(str, word)))
        return

    for idx in range(N):
        if check[idx]:
            continue
        else:
            check[idx] = True
            word[count] = idx + 1
            DFS(idx, check, word, N, count+1)
            word[count] = 0
            check[idx] = False

def solution():
    N = int(sys.stdin.readline())

    word = [0 for _ in range(N)]
    check = [False for _ in range(N)]

    for idx in range(N):
        check[idx] = True
        word[0] = idx + 1
        DFS(idx, check, word, N, 1)
        word[0] = 0
        check[idx] = False

solution()

https://www.acmicpc.net/problem/10974

Categories:

Updated:

Leave a comment