汉诺塔系列1
Time Limit: 1000MS Memory Limit: 65536KB
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
对于每组数据,输出移动过程中所有会产生的系列总数。
Example Input
3
1
3
29
Example Output
3
27
68630377364883
Hint
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
long long f;
int n,i;
scanf("%d",&i);
while(i--)
{
scanf("%d",&n);
f=pow(3,n);
printf("%ld\n",f);
}
return 0;
}