0
点赞
收藏
分享

微信扫一扫

HDU 2064 汉诺塔III


Description



约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下、由小到大顺序串着由64个圆盘构成的塔。目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动一个盘,且不允许大盘放在小盘的上面。 
现在我们改变游戏的玩法,不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到下盘的上面。 
Daisy已经做过原来的汉诺塔问题和汉诺塔II,但碰到这个问题时,她想了很久都不能解决,现在请你帮助她。现在有N个圆盘,她至少多少次移动才能把这些圆盘从最左边移到最右边? 


Input



包含多组数据,每次输入一个N值(1<=N=35)。



 


Output



对于每组数据,输出移动最小的次数。



 


Sample Input


1
3
12

 


Sample Output

2
26
531440


找规律递推一下就好了



#include<iostream>  
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;
const int low(int x){ return x&-x; }
int T, n;
LL f[maxn];

int main(){
//scanf("%d", &T);
for (int i = 1; i <= 35; i++) f[i] = f[i - 1] * 3 + 2;
while (~scanf("%d", &n))
{
printf("%lld\n", f[n]);
}
return 0;
}



举报

相关推荐

0 条评论