사생활 보호 설정
https://gamjia.tistory.com
Updated News
Mini Rooms
답글수 [0]
What Friends Say
한마디로 표현해봐~
1촌평 관리
11729번 하노이 탑 이동 순서
GamJia 2023. 3. 31. 09:16
단계별로 풀어보기 - 재귀 - 4단계
https://www.acmicpc.net/problem/11729
#include <iostream> #include <cmath> using namespace std; void hanoi(int N,int first,int middle,int last) { if(N==1) { cout<<first<<" "<<middle<<"\n"; } else { hanoi(N-1,first,last,middle); cout<<first<<" "<<middle<<"\n"; hanoi(N-1,last,middle,first); } } int main() { int num; cin>>num; cout<<(int)pow(2,num)-1<<"\n"; hanoi(num,1,3,2); }