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 ;
}

最新文章

  1. 根据oracle的主键列生成SQLserver的主键
  2. Android引用项目出现ClassNotFoundException
  3. jQuery cdn使用介绍
  4. 3D Touch集成过程整理
  5. js 创建书签小工具之理论
  6. 源码安装Apache,报错:Cannot use an external APR with the bundled APR-util和httpd: Could not reliably determine the server&#39;s fully qualified domain name, using
  7. oracle 基本语句练习(一) where, between ,null, like,转义字符,order by
  8. Java文件File操作一:文件的创建和删除
  9. 上传XML文件字符编码问题
  10. 2台linux机器免密码互相登陆
  11. UE4 字符串的转换
  12. Photoshop给草坡上的人物加上大气的霞光
  13. IIC时序操作24C02芯片
  14. [转帖]你云我云•兄弟夜谈会 第三季 企业IT架构
  15. 元素滚动到底部或顶部时阻止body滚动
  16. ubuntu服务器搭建DVWA站点
  17. 排错-Loadrunner添加Windows&#160;Resource计数器提示“找不到网络路径”解决方法
  18. iOS上的http请求:get、post以及同步、异步
  19. 2018-2019-2 20165330《网络对抗技术》Exp2 后门原理与实践
  20. Java并发学习之十五——使用读写锁同步数据訪问

热门文章

  1. StringBuffer和String的相互转换
  2. 协议端口号(protocol port number)
  3. JAVA多线程---高并发程序设计
  4. Bit Byte WORD DWORD的区别和联系
  5. JSP入门 导出文件
  6. uva1267 Network
  7. EnCase missed some usb activities in the evidence files
  8. 当前页面的url未注册 微信支付
  9. javascript特效300例----抄书喽
  10. Redis Windows版安装详解