汉诺塔系列1
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
n个盘子的汉诺塔问题的最少移动次数是2^n-1,即在移动过程中会产生2^n个系列。由于发生错移产生的系列就增加了,这种错误是放错了柱子,并不会把大盘放到小盘上,即各柱子从下往上的大小仍保持如下关系 :
n=m+p+q
a1>a2>…>am
b1>b2>…>bp
c1>c2>…>cq
计算所有会产生的系列总数。
Input
包含多组数据,首先输入T,表示有T组数据.每个数据一行,是盘子的数目N<30。
Output
对于每组数据,输出移动过程中所有会产生的系列总数。
Sample Input
3
1
3
29
Sample Output
3
27
68630377364883
Hint
这里写代码片#include<stdio.h>
int main()
{
int i;
long long int a[31];
a[1]=3;
int p=3;
for(i=2;i<=30;i++)
{
a[i]=a[i-1]*p;
}
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%lld\n",a[n]);
}
return 0;
}