#BOJ 1914 하노이탑

Wonder_Why (Today I learned)·2022년 3월 1일
0

BOJ

목록 보기
70/70
post-thumbnail

BOJ 1914 하노이탑

(https://www.acmicpc.net/problem/1914)

  • C++ 로 풀려면 big integer 을 구현해야해서 일단 python 으로 풀었다.
def hanoi(start, goal, assi, n):
    if n == 1:
        print(start, goal, sep= " ")
    else:
        hanoi(start, assi, goal, n - 1)
        hanoi(start, goal, assi, 1)
        hanoi(assi, goal, start, n - 1)


n = int(input())
print(2**n-1)
if n <= 20:
    hanoi(1, 3, 2, n)
profile
전자과 머학생

0개의 댓글