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
根据题意很容易发现f[n]=f[n-1]+f[n-2];只要看到这一点,那这一题就迎刃而解了;
#include<algorithm>  
#include<iostream>  
#include<cstdio>  
#include<cstring>  
using namespace std;  
const int mod=1e9+7;   
const int maxc=1000+10;  
int f[maxc];  
void x(int y)  
{  
    int i,j;  
    f[1]=1;f[2]=2;  
    for(i=3;i<=y;i++)
    f[i]=(f[i-1]+f[i-2])%mod;  
}  
int main()  
{  
    int i,j,n;  
   
    cin>>n; 
    x(n);  
    cout<<f[n]<<endl;  
    return 0;  
}  

 

 

  

posted @ 2017-03-12 10:59  一点绝不是微小  阅读(108)  评论(0)    收藏  举报