Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

HDU1996:汉诺塔VI

$
0
0
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
 


 

我会说我一看到样例输出就知道公式是3^n么

= =

#include <stdio.h>
__int64 pow(int n)
{
    __int64 s = 1;
    for(int i = 1;i<=n;i++)
    s*=3;
    return s;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int a;
        __int64 ans;
        scanf("%d",&a);
        ans = pow(a);
        printf("%I64d\n",ans);

    }

    return 0;
}

作者:libin56842 发表于2013-4-26 13:01:28 原文链接
阅读:56 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>