https://www.acmicpc.net/problem/11729
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
void CPP_INIT() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void hanoi(int n, int from, int by, int to) {
if (n == 1) {
cout << from << " " << to << endl;
}
else {
hanoi(n - 1, from, to, by);
cout << from << " " << to << endl;
hanoi(n - 1, by, from, to);
}
}
int main(void) {
CPP_INIT();
int input;
cin >> input;
cout << int(pow(2, input)) - 1 << endl;
hanoi(input, 1, 2, 3);
}
'알고리즘' 카테고리의 다른 글
C++ 알고리즘 - 백준 25501 재귀의 귀재 (참조자 문자열) (0) | 2025.01.17 |
---|---|
C++ 알고리즘 - 백준 10870 피보나치 수 5 (0) | 2025.01.17 |
C++ 알고리즘 - 백준 20920 영단어 암기는 괴로워 (맵, 벡터) (0) | 2025.01.17 |
C++ 알고리즘 - 백준 26069 붙임성 좋은 총총이 (0) | 2025.01.16 |
C++ 알고리즘 - 백준 25192 인사성 밝은 곰곰이 (0) | 2025.01.16 |