[백준] 11729번: 하노이의 탑 이동순서

yewon Lee·2023년 9월 10일
0


😎BACKJOON>11729번: 하노이의 탑 이동순서


📘 문제풀이

import sys
n = int(sys.stdin.readline())

def move(N, start, to):
    print(start, to)
    
def hanoi(N, start, to, via):
    if N == 1:
        move(1, start, to)
    else:
        hanoi(N-1, start, via, to)
        move(N, start, to)
        hanoi(N-1, via, to, start)
print(2**n-1)
hanoi(n, 1, 3, 2)
profile
시작

0개의 댓글