HDU 2046 骨牌铺方格

http://acm.hdu.edu.cn/showproblem.php?pid=2046

Problem Description
在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.
例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:
 
Input
输入数据由多行组成,每行包含一个整数n,表示该测试实例的长方形方格的规格是2×n (0<n<=50)。
 
Output
对于每个测试实例,请输出铺放方案的总数,每个实例的输出占一行。
 
Sample Input
1
3
2
 
Sample Output
1
3
2
 
题解:斐波那切数列
代码:
#include <bits/stdc++.h>

using namespace std;

long long int a[55];

int main()
{
    for(int i=1; i<=50; i++)
    {
        if(i<=3)
            a[i]=i;
        else
            a[i]=a[i-1]+a[i-2];
    }
    int x;
    while(~scanf("%d",&x))
    {
        printf("%lld\n",a[x]);
    }
    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/zlrrrr/p/9347073.html
今日推荐