#include<iostream>
using namespace std;
const int N =10;
int a[N];
int dfs(int dep){//dep表示当前的深度
int ans=1;
for(int i=1;i<=a[dep-1]/2;++i){
a[dep]=i;
ans+=dfs(dep+1);
}
return ans;
}
int main(){
int n;cin>>n;
a[1]=n;
cout<<dfs(2)<<endl;
return 0;
}
1.汉诺塔
#include<iostream>
//#include<bits/stdc++>
#include<algorithm>
#include<math.h>
using namespace std;
enum tower{ A='X',B='Y',C='Z'
};
void Move(int n,tower x,tower y){
cout<<"move "<<n<<" from "<<char(x)<<" to "<<char(y)<<endl;
}
void Hanoi(int n,tower x,tower y,tower z){
//n:x-->y
if(n){
Hanoi(n-1,x,z,y);//n-1:x--(y)-->z
Move(n,x,y);//n:x-->y
Hanoi(n-1,z,y,x); //n-1:z--(y)-->x
}
}
int main(){
int n;cin>>n;
Hanoi(n,A,B,C);
}