题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=2064
汉诺塔变种,只能从中间专业,递归关系为:f(n)=3*f(n-1)+2.
1 //汉诺塔变种,只能从中间转移 2 //11485816 2014-08-19 08:44:47 Accepted 2064 0MS 368K 307 B G++ 空信高手 3 #include<iostream> 4 #include<cstdio> 5 using namespace std; 6 #define LL long long 7 int main() 8 { 9 //freopen("input.txt","r",stdin); 10 LL Sum[35]; 11 int n=0; 12 Sum[0] = 0; 13 Sum[1] = 2; 14 for(int i=2;i<=35;i++) 15 { 16 Sum[i]=3*Sum[i-1]+2; 17 } 18 while(cin>>n) 19 cout<<Sum[n]<<endl; 20 return 1; 21 22 }
[acm]HDOJ 2064 汉诺塔III,布布扣,bubuko.com
原文:http://www.cnblogs.com/panweishadow/p/3921199.html