1 count=0 2 def hanoi(n,src,dst,mid): 3 global count 4 if n==1: 5 print("{}:{}->{}".format(1,src,dst)) 6 count+=1 7 else: 8 hanoi(n-1,src,mid,dst) 9 print("{}:{}->{}".format(n,src,dst)) 10 count+=1 11 hanoi(n-1,mid,dst,src) 12 n=eval(input()) 13 hanoi(n,"A","C","B") 14 print(count)
原文:https://www.cnblogs.com/lxw2020/p/12595410.html