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
 
打表
/*
* @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=;
while(x){
if(x%==){
res++;
}else{
if(res%==) return false;
else res=;
}
x/=;
}
if(res%==) return false;
else return true;
} inline void init(){
memset(dp,,sizeof dp);
} int main(){
freopen("in.txt","r",stdin);
for(int n=;n<=;n++){
init();
for(int i=;i<=MAXK;i++){//初始化第一行的没种状态
if(ok(i)==true)
dp[][i]=;
}
for(int i=;i<n;i++){
for(int j=;j<=MAXK;j++){
if(dp[i][j]!=){
for(int k=;k<=MAXK;k++){
if( (j|k)==MAXK && ok(j&k) )
///j|k==tot-1的话就是能拼起来组成
dp[i+][k]+=dp[i][j];
}
}
}
}
printf("%d\n",dp[n][MAXK]);
}
return ;
}
/*
* @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,,sizeof(a));
if (x)
for (int i = ; i < MAXN ; i++)
a[i][i] = 1LL;
} Matrix operator +(Matrix b) {
Matrix c;
c.n = n;
for (int i = ; i < n; i++)
for (int j = ; 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 = ; i < n; i++)
c.a[i][i] += x;
return c;
} Matrix operator *(Matrix b)
{
Matrix p;
p.n = b.n;
p.init();
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
for (int k = ; 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();
while (t) {
if (t & )
ans=ans*p;
p = p*p;
t >>= ;
}
return ans;
}
}init,unit;
/********************************矩阵快速幂**********************************/ LL n; int main(){
// freopen("in.txt","r",stdin);
while(scanf("%lld",&n)!=EOF){
if(n<=){
switch(n){
case :
puts("");
break;
case :
puts("");
break;
case :
puts("");
break;
case :
puts("");
break;
}
continue;
}
init.init();
init.n=;
init.a[][]=;
init.a[][]=;
init.a[][]=;
init.a[][]=;
unit.init();
unit.n=;
unit.a[][]=;
unit.a[][]=;
unit.a[][]=;
unit.a[][]=-;
unit.a[][]=;
unit.a[][]=;
unit.a[][]=;
unit=unit.power(n-);
init=init*unit;
printf("%lld\n",(init.a[][]+mod)%mod);
}
return ;
}

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

  1. 2017ACM/ICPC广西邀请赛 1004 Covering

    Covering Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  2. 2017 ICPC 广西邀请赛1005 CS Course

    CS Course Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering

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

  4. 2017 ACM/ICPC 广西邀请赛 题解

    题目链接  Problems HDOJ上的题目顺序可能和现场比赛的题目顺序不一样, 我这里的是按照HDOJ的题目顺序来写的. Problem 1001 签到 #include <bits/std ...

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

    上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3 ...

  6. 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi

    Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...

  7. 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree

    Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...

  8. 2017ACM/ICPC广西邀请赛-重现赛

    HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...

  9. HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序

    题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...

随机推荐

  1. Webx项目的获取与验证

    在JavaWeb环境配置后就可进行Webx实例项目的获取与研读了. 1.创建一个初始的Demo工程. 1)下载 Webx Maven 项目的目录结构Artifact插件. archetype-webx ...

  2. 概率图论PGM的D-Separation(D分离)

    目录[-] 本文大部分来自:http://www.zhujun.me/d-separation-separation-d.html 一.引言 二.三种情况分析 三.总结 四.应用例子 五.参考资料 其 ...

  3. Windows下memcached的安装配置

    下载windows 32位或64位 memcached 下载 memcached_dll 1.将第一个包解压放某个盘下面,比如在c:\memcached.2.在终端(也即cmd命令界面)下输入 'c: ...

  4. Python系列之反射、面向对象

    一.反射 说反射之前先介绍一下__import__方法,这个和import导入模块的另一种方式 1. import commons 2. __import__('commons') 如果是多层导入: ...

  5. HDU1212

    大数MOD #include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm& ...

  6. Java面向对象 GUI 补录

     Java面向对象 GUI 补录 知识概要:(1)GUI和CLI                   (2)AWT和SWING                   (3)AWT继承关系图      ...

  7. winPcap编程之不用回调方法捕获数据包(五 转)

    这一次要分析的实例程序跟上一讲非常类似(“打开适配器并捕获数据包”),略微不同的一点是本次将pcap_loop()函数替换成了pcap_next_ex()函数.本节的重点也就是说一下这两个函数之间的差 ...

  8. 【学习】jquery.placeholder.js让IE浏览器支持html5的placeholder

    type为text或password的input,其在实际应用时,往往有一个占位符,类似这样的: 在没有html5前,一般写成value,用js实现交互,文本框获得焦点时,提示文字消失,失去焦点时,文 ...

  9. visual studio 2015 warning MSB3246

    在我们很高兴的按下 本地计算机运行 按钮,希望看到我们程序运行的时候,垃圾vs就告诉我们,你的程序出现了问题,问题就是: warning MSB3246: 解析的文件包含错误图像.无元数据或不可访问. ...

  10. win10 uwp 保存用户选择文件夹

    如果我们每次把临时处理的文件保存,都要让用户选择一次,用户会不会觉得uwp垃圾?如果我们每次打开应用,都从某个文件读取,而这个文件不在应用目录和已知的目录,那么每次都需要用户选择,用户会不会觉得uwp ...