51nod 1031 骨牌覆盖

基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题
 收藏
 关注
在2*N的一个长方形方格中,用一个1*2的骨牌排满方格。
问有多少种不同的排列方法。

例如:2 * 3的方格,共有3种不同的排法。(由于方案的数量巨大,只输出 Mod 10^9 + 7 的结果)
Input
输入N(N <= 1000)
Output
输出数量 Mod 10^9 + 7
Input示例
3
Output示例
3

题解:通过找规律可以发现是斐波那契数列。



#include<iostream>
using namespace std;

const int maxn=1010;

typedef long long ll;
const int mod=1e9+7;
ll dp[maxn];


int main()
{
    ll n;
    dp[0]=dp[1]=1;
    for(ll i=2;i<maxn;i++)
    {

        dp[i]=(dp[i-1]+dp[i-2])%mod;
    }
    cin>>n;
    cout<<dp[n]<<endl;

    return 0;
}





posted @ 2017-11-24 20:24  Bryce1010  阅读(65)  评论(0编辑  收藏  举报