http://acm.hdu.edu.cn/showproblem.php?pid=2064
现在我们改变游戏的玩法,不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到下盘的上面。
Daisy已经做过原来的汉诺塔问题和汉诺塔II,但碰到这个问题时,她想了很久都不能解决,现在请你帮助她。现在有N个圆盘,她至少多少次移动才能把这些圆盘从最左边移到最右边?
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
ll dp[36][2];
void init()
{
dp[1][0]=1,dp[1][1]=1;
for(int i=2;i<36;i++) dp[i][0]+=dp[i-1][0]*2+dp[i-1][1]+1,dp[i][1]+=dp[i-1][0]+2*dp[i-1][1]+1;
}
int main()
{
// freopen("1.txt","r",stdin);
init();
int n;
while(scanf("%d",&n)!=EOF)
{
cout<<dp[n-1][0]*3+3*dp[n-1][1]+2<<'\n';
}
return 0;
}