汉诺塔系列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
Think:此类题目代码简单,但不易找到规律。并且,要注意数据的范围, 用long long 来处理。
Author
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int a, b; scanf("%d", &a); while(a--) { scanf("%d", &b); int i; long long int f[35]; f[1] = 3; for(i=2;i<=b;i++) f[i] = 3 * f[i-1]; printf("%lld\n", f[b]); } return 0; }
感觉好难过啊,居然要用递归做,看来以后不能省事了,机测前又要重做。。。。。。
(修改后)