51Nod 1031 骨牌覆盖 | Fibonacci

Input
输入N(N <= 1000)
Output
输出数量 Mod 10^9 + 7
Input示例
3
Output示例
3

思路:对于第x块骨牌的情况,我们用a[x]表示其方法数;其比x-1块骨牌时多了一块骨牌,多出的骨牌有两种放法:

1.我们可以直接将其竖着添加在最末端,那么其排列数就为就是前x-1块骨牌的排列数,即为a[x-1];

2. 我们也可以将其和其前面一块骨牌一起横着放,那么其排列数就是前x-2块骨牌的排列数,即为a[x-2];

所以有 a[x]=a[x-1]+a[x-2];

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i,a,n) for(int i = a; i < n; i++)
#define repe(i,a,n) for(int i = a; i <= n; i++)
#define per(i,n,a) for(int i = n; i >= a; i--)
#define clc(a,b) memset(a,b,sizeof(a))
#define INF 1e18+100
#define N 1010
#define MOD 1010
typedef long long LL;

const int mod=1e9+7;

int main(){
    int a[N], n;
    a[0]=1, a[1]=1;
    scanf("%d",&n);
    for(int i=2; i<=n; i++){
        a[i]=(a[i-1]+a[i-2])%mod;
    }
    printf("%d
",a[n]);
    return 0;
}

感谢:http://www.cnblogs.com/geloutingyu/p/6280350.html

原文地址:https://www.cnblogs.com/kimsimple/p/7465710.html