ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

10974๋ฒˆ: ๋ชจ๋“  ์ˆœ์—ด

N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, 1๋ถ€ํ„ฐ N๊นŒ์ง€์˜ ์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ ์ˆœ์—ด์„ ์‚ฌ์ „์ˆœ์œผ๋กœ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

 N์ด ์ฃผ์–ด์ง€๋ฉด 1๋ถ€ํ„ฐ N๊นŒ์ง€์˜ ์ˆ˜ ์ค‘์— N์˜ ๊ธธ์ด์— ํ•ด๋‹นํ•˜๋Š” ์ˆœ์—ด์„ ์ฐพ๋Š” ๋ฌธ์ œ์ด๋‹ค. ์•ž์„œ ํ‘ผ N๊ณผ M ์‹œ๋ฆฌ์ฆˆ๋ฅผ ํ†ตํ•ด ์ˆœ์—ด์„ ๊ตฌํ•˜๋Š” ๋ฒ•์„ ์•Œ๊ณ  ์žˆ์œผ๋ฏ€๋กœ ์ด ๋ฌธ์ œ๋Š” ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋‹ค.

 

์ฝ”๋“œ

from sys import stdin


def dfs(depth):
    global answer

    if depth == n:
        answer.append([num for num in check])
    else:
        for i in range(n):
            if i + 1 in check:
                continue
            check[depth] = i + 1
            dfs(depth + 1)
            check[depth] = 0

if __name__ == '__main__':
    answer = []
    n = int(stdin.readline())
    check = [0] * n
    dfs(0)

    for case in answer:
        print(*case)
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€