Covering

 
Bob's school has a big playground, boys and girls always play games here after school. 

To protect boys and girls from getting hurt when playing happily on the playground, rich boy Bob decided to cover the playground using his carpets. 

Meanwhile, Bob is a mean boy, so he acquired that his carpets can not overlap one cell twice or more. 

He has infinite carpets with sizes of 4×n. 

Can you tell Bob the total number of schemes where the carpets can cover the playground completely without overlapping? 

InputThere are no more than 5000 test cases. 

Each test case only contains one positive integer n in a line. 

1≤n≤1018 
OutputFor each test cases, output the answer mod 1000000007 in a line. 
Sample Input

1
2

Sample Output

1
5


题意:用1*2铺满4*n的地面。
特别综合的一道题。求法是先用模拟暴搜找出初始几个n的情况,//1 5 11 36 95 281 781 2245 6336 18061
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MAX 1005
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long ll;

int b[5][MAX];
int n;
ll ans;

void dfs(int s){
    int i,j;
    if(s==4*n){
        ans++;
        return;
    }
    for(i=1;i<=4;i++){
        for(j=1;j<=n;j++){
            if(b[i][j]==0){
                if(i+1<=4){
                    if(b[i+1][j]==0){
                        b[i][j]=1;
                        b[i+1][j]=1;
                        dfs(s+2);
                        b[i][j]=0;
                        b[i+1][j]=0;
                    }
                }
                if(j+1<=n){
                    if(b[i][j+1]==0){
                        b[i][j]=1;
                        b[i][j+1]=1;
                        dfs(s+2);
                        b[i][j]=0;
                        b[i][j+1]=0;
                    }
                }
                return;
            }
        }
    }
}
int main()
{
    int i;
    while(~scanf("%d",&n)){
        memset(b,0,sizeof(b));
        ans=0;
        dfs(0);
        printf("%lld\n",ans);    
    }
    return 0;
}
View Code

相关文章: