骨牌铺方格 HDU - 2046

滴答滴答---题目链接 

在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 <iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
ll dp[61];
int n;
int main()
{
    dp[1]=1;
    dp[2]=2;
    for(int i=3; i<=50; i++)
    {
        dp[i]=dp[i-1]+dp[i-2];
    }
    while(~scanf("%d",&n))
    {
        printf("%lld\n",dp[n]);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/chen_zan_yu_/article/details/84450343