-
Notifications
You must be signed in to change notification settings - Fork 0
/
14. Tower of Hanoi.cpp
37 lines (32 loc) · 959 Bytes
/
14. Tower of Hanoi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "iostream"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef set<ll> sl;
typedef map<char, ll> mcl;
typedef pair<char, ll> pcl;
#define PB push_back
#define F first
#define S second
#define REP(i,a,b) for (ll i = a; i < b; i++)
#define REPR(i,a,b) for (ll i = a; i > b; i--)
#define REPJ(i,a,b,j) for (ll i = a; i < b; i+=j)
#define REPIT(it,o) for (auto it = o.begin(); it != o.end(); it++)
#define REPITR(it,o) for (auto it = o.rbegin(); it != o.rend(); it++)
void rec(ll n, string primary, string secondary, string intermediate){
if (n == 1){
cout << primary << " " << secondary << "\n";
return;
}
rec(n-1, primary, intermediate, secondary);
cout << primary << " " << secondary << "\n";
rec(n-1, intermediate, secondary, primary);
}
int main() {
ll n;
cin >> n;
cout << pow(2,n)-1 << "\n";
rec(n,"1", "3", "2");
}