2017 ICPC 广西邀请赛1004 Covering

Covering

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 187    Accepted Submission(s): 107

Problem Description

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 1×2 and 2×1, and the size of the playground is 4×n.

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

Input

There are no more than 5000 test cases.

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

1≤n≤1018

Output

For each test cases, output the answer mod 1000000007 in a line.

Sample Input

1
2

Sample Output

1
5

Source

2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)

打表

/*
* @Author: Administrator
* @Date:   2017-08-31 17:40:04
* @Last Modified by:   Administrator
* @Last Modified time: 2017-09-01 11:03:00
*/
/*
 题意:给你一个4*n的矩阵,然后让你用1*2和2*1的木块放,问你完美覆盖的
    方案数

 思路:状压DP找规律
*/

#include <bits/stdc++.h>

#define MAXN 100
#define MAXM 20
#define MAXK 15
using namespace std;

int dp[MAXN][MAXM];//dp[i][j]表示前ihang
int n;

inline bool ok(int x){
    //判断是不是有连续个1的个数是奇数
    int res=0;
    while(x){
        if(x%2==1){
            res++;
        }else{
            if(res%2==1) return false;
            else res=0;
        }
        x/=2;
    }
    if(res%2==1) return false;
    else return true;
}

inline void init(){
    memset(dp,0,sizeof dp);
}

int main(){
    freopen("in.txt","r",stdin);
    for(int n=1;n<=50;n++){
        init();
        for(int i=0;i<=MAXK;i++){//初始化第一行的没种状态
            if(ok(i)==true)
                dp[1][i]=1;
        }
        for(int i=1;i<n;i++){
            for(int j=0;j<=MAXK;j++){
                if(dp[i][j]!=0){
                    for(int k=0;k<=MAXK;k++){
                        if( (j|k)==MAXK && ok(j&k) )
                            ///j|k==tot-1的话就是能拼起来组成
                            dp[i+1][k]+=dp[i][j];
                    }
                }
            }
        }
        printf("%d\n",dp[n][MAXK]);
    }
    return 0;
}
/*
* @Author: Administrator
* @Date:   2017-09-01 11:17:37
* @Last Modified by:   Administrator
* @Last Modified time: 2017-09-01 11:28:09
*/
#include <bits/stdc++.h>

#define MAXN 5
#define mod 1000000007
#define LL long long

using namespace std;

/********************************矩阵快速幂**********************************/
class Matrix {
    public:
        LL a[MAXN][MAXN];
        LL n;  

        void init(LL x) {
            memset(a,0,sizeof(a));
            if (x)
                for (int i = 0; i < MAXN ; i++)
                    a[i][i] = 1LL;
        }

        Matrix operator +(Matrix b) {
            Matrix c;
            c.n = n;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    c.a[i][j] = (a[i][j] + b.a[i][j]) % mod;
            return c;
        }

        Matrix operator +(LL x) {
            Matrix c = *this;
            for (int i = 0; i < n; i++)
                c.a[i][i] += x;
            return c;
        }

        Matrix operator *(Matrix b)
        {
            Matrix p;
            p.n = b.n;
            p.init(0);
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++)
                    p.a[i][j] = (p.a[i][j] + (a[i][k]*b.a[k][j])%mod) % mod;
            return p;
        }

        Matrix power(LL t) {
            Matrix ans,p = *this;
            ans.n = p.n;
            ans.init(1);
            while (t) {
                if (t & 1)
                    ans=ans*p;
                p = p*p;
                t >>= 1;
            }
            return ans;
        }
}init,unit;
/********************************矩阵快速幂**********************************/

LL n;

int main(){
    // freopen("in.txt","r",stdin);
    while(scanf("%lld",&n)!=EOF){
        if(n<=4){
            switch(n){
                case 1:
                    puts("1");
                    break;
                case 2:
                    puts("5");
                    break;
                case 3:
                    puts("11");
                    break;
                case 4:
                    puts("36");
                    break;
            }
            continue;
        }
        init.init(0);
        init.n=4;
        init.a[0][0]=36;
        init.a[0][1]=11;
        init.a[0][2]=5;
        init.a[0][3]=1;
        unit.init(0);
        unit.n=4;
        unit.a[0][0]=1;
        unit.a[1][0]=5;
        unit.a[2][0]=1;
        unit.a[3][0]=-1;
        unit.a[0][1]=1;
        unit.a[1][2]=1;
        unit.a[2][3]=1;
        unit=unit.power(n-4);
        init=init*unit;
        printf("%lld\n",(init.a[0][0]+mod)%mod);
    }
    return 0;
}
时间: 2024-10-29 19:08:11

2017 ICPC 广西邀请赛1004 Covering的相关文章

2017 ICPC 广西邀请赛1005 CS Course

CS Course Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Little A has come to college and majored in Computer and Science. Today he has learne

2017 ACM/ICPC 广西邀请赛 题解

题目链接  Problems HDOJ上的题目顺序可能和现场比赛的题目顺序不一样, 我这里的是按照HDOJ的题目顺序来写的. Problem 1001 签到 #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) typedef long long LL; LL n, f[31]; int ans; int main(){ f[1] = 1LL; fo

2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)

A Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description You are given a positive integer n, please count how many positive integers k sa

2017广西邀请赛 Query on A Tree (可持续化字典树)

Query on A Tree 时间限制: 8 Sec  内存限制: 512 MB提交: 15  解决: 3[提交][状态][讨论版] 题目描述 Monkey A lives on a tree. He always plays on this tree.One day, monkey A learned about one of the bit-operations, xor. He was keen of this interesting operation and wanted to pr

HDU6186 2017广西邀请赛 CS Course (前缀和后缀)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6186 思路:题目要求的删除第q个数候所有数的 & | ^和,所以提前求出前缀和后缀,每次& | ^ 前i-1个和后i+1个即可.注意a^b^b=a; #include <iostream> #include <cstdio> using namespace std; const long long maxn=1e5+10; int n,q; long long f1[m

icpc南昌邀请赛 比赛总结

上周末,我参加了icpc南昌区域赛邀请赛,这也是我的第一次外出参赛. 星期五晚上,在6个小时的火车和1个小时的公交后,我们终于抵达了江西师范大学,这次的比赛场地.江西师范大学周围的设施很齐全,各种烧烤,大型商场,地铁应有尽有,去酒店办好入住手续,放下东西后,我们便去吃饭,听说南昌的小龙虾很不错,我们就选择了一家烧烤店吃起了烧烤.还是很高兴的,就是因为吃太多了晚上睡不着有点休息不好. 第二天早上,大家都起到很晚,我9点钟醒时还没有人醒,等到10:30我们一起去签到,收获了自己的第一件参赛衣服,同时

2017 ICPC区域赛(西安站)--- J题 LOL(DP)

题目链接 problem description 5 friends play LOL together . Every one should BAN one character and PICK one character . The enemy should BAN 55 characters and PICK 55 characters . All these 2020 heroes must be different . Every one can BAN any heroes by h

Bumped! 2017 ICPC North American Qualifier Contest (分层建图+dijstra)

题目描述 Peter returned from the recently held ACM ICPC World finals only to find that his return flight was overbooked and he was bumped from the flight! Well, at least he wasn’t beat up by the airline and he’s received a voucher for one free flight bet

2017 ICPC西安区域赛 A - XOR (线段树并线性基)

链接:https://nanti.jisuanke.com/t/A1607 题面: Consider an array AA with n elements . Each of its element is A[i]A[i] (1 \le i \le n)(1≤i≤n) . Then gives two integers QQ, KK, and QQ queries follow . Each query , give you LL, RR, you can get ZZ by the foll