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. OC——关于KVC

    我们知道在C#中可以通过反射读写一个对象的属性,有时候这种方式特别方便,因为你可以利用字符串的方式去动态控制一个对象.其实由于ObjC的语言特性,你根部不必进行任何操作就可以进行属性的动态读写,这种方 ...

  2. Python之面向对象与类

    本节内容 面向对象的概念 类的封装 类的继承 类的多态 静态方法.类方法 和 属性方法 类的特殊成员方法 子类属性查找顺序 一.面向对象的概念 1. "面向对象(OOP)"是什么? ...

  3. xml跟sql查找

    xml小白笔记 ....... <sql id="wDishesColumns"> a.id AS "id", a.pid AS "pid ...

  4. this的四种绑定形式

    一 , this的默认绑定 当一个函数没有明确的调用对象的时候,也就是单纯作为独立函数调用的时候,将对函数的this使用默认绑定:绑定到全局的window对象. 一个例子 function fire ...

  5. .NetCore之下载文件

    本篇将和大家分享的丝.NetCore下载文件,常见的下载有两种:A标签直接指向下载文件地址和post或get请求后台输出文件流的方式,本篇也将围绕这两种来分享:如果对您有好的帮助,请多多支持. 允许站 ...

  6. React获得真实的DOM操作

    真实的DOM操作 ------------------------------------------------------------------------------------------- ...

  7. 关于MySQL 事务,视图,索引,数据库备份,恢复

      /*创建数据库*/ CREATE DATABASE `mybank`;/*创建表*/USE mybank;CREATE TABLE `bank`(    `customerName` CHAR(1 ...

  8. Android 从ImageView中获取Bitmap对象方法

    showImageView.setDrawingCacheEnabled(true); Bitmap bitmap=showImageView.getDrawingCache(); showImage ...

  9. FPGA在其他领域的应用(三)

    广播领域: 专业的A/V(音频/视频),和演播室行业正在经历着激动人心的变化,例如,UHD/8K (超高清)视频.多平台内容交付.IP网络传输和云计算.2016里约奥运会使用4K分辨率视频播放,而日本 ...

  10. tesseract-ocr字库训练图文讲解

    第一步合成图片集 你需要把使用jTessBoxEditor工具把你的训练素材及多张图片合并成一张tif格式的图片集 第二步  生成box文件 运行tesseract命令,tesseract mjorc ...