题干:

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×21×2 and 2×12×1, and the size of the playground is 4×n4×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≤10181≤n≤1018

Output

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

Sample Input

1
2

Sample Output

1
5

题目大意:

给一个4*n的格子,你有两种方块(1*2),(2*1),放置的同时不能交叉重叠,询问放满的方案数。(n<=1e18)

解题报告:

考虑几种可行的状态:①0000,②1100,③0110,④0011,⑤1001,⑥1111。分别转移即可。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const ll mod = 1e9 + 7;
const int MAX = 9;
struct Matrix {ll m[MAX][MAX];
} unix;
Matrix Mul(Matrix a,Matrix b) {Matrix c;memset(c.m,0,sizeof c.m);for(int i = 1; i<=6; i++) {for(int j = 1; j<=6; j++) {for(int k = 1; k<=6; k++) {c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j])%mod;}}}return c;
}
Matrix qpow(Matrix a,ll k) {Matrix res = unix;while(k) {if(k&1) res = Mul(res,a);a = Mul(a,a);k>>=1;}return res;
}
int main()
{   ll n;for(int i = 1; i<=6; i++) {unix.m[i][i] = 1;}Matrix trans;memset(trans.m,0,sizeof trans.m);trans.m[1][6]=trans.m[2][4]=trans.m[2][6]=trans.m[3][5]=trans.m[3][6]=trans.m[4][2]=trans.m[4][6]=trans.m[5][3]=1;trans.m[6][1]=trans.m[6][2]=trans.m[6][3]=trans.m[6][4]=trans.m[6][6]=1;while(~scanf("%lld",&n)) {Matrix ans = qpow(trans,n+1);printf("%lld\n",ans.m[1][6]);}return 0 ;
}

另一个题解:

https://blog.csdn.net/qq_32570675/article/details/77816353

【HDU - 6185】Covering(矩阵快速幂优化二维dp,高斯消元,轮廓线dp打表)相关推荐

  1. HDU 6185 Covering 矩阵快速幂 递推

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6185 题目描述: 一个4*n的矩形, 你用1*2的矩形覆盖有多少种方案, n <= 1e18 ...

  2. hdu 6185 Covering 矩阵快速幂

    题意: 用1*2和2*1的两种地毯铺地 问有多少种情况 思路: 直接推转移方程 从An-1的地方只有1种转移方法 从An-2的地方有5种转移方法 n-3转移不到n 但是n-4可以 也是最复杂的 从An ...

  3. 【bzoj1778】[Usaco2010 Hol]Dotp 驱逐猪猡 矩阵乘法+概率dp+高斯消元

    题目描述 奶牛们建立了一个随机化的臭气炸弹来驱逐猪猡.猪猡的文明包含1到N (2 <= N <= 300)一共N个猪城.这些城市由M (1 <= M <= 44,850)条由两 ...

  4. HDU - 5667 Sequence(矩阵快速幂+费马小定理降幂)

    题目链接:点击查看 题目大意:给出函数f(x): 现给出n,a,b,c,mod,求f(n)对mod取模后的结果 题目分析:这个题目相对于前几个题来说稍微加大了点难度,但还是挺水的一个题,首先我们可以对 ...

  5. hdu 6395Sequence【矩阵快速幂】【分块】

    Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total ...

  6. HDU 2256(矩阵快速幂)

    传送门 题面: Problem of Precision Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  7. HDU 4382 【矩阵快速幂】【欧拉降幂】

     自己的思路写的 102 × 102 大小的转化矩阵,好在线代学的还行想到用矩阵分块乘法过了- 看其他人的题解用的 3 × 3  构造一个 转化矩阵 T T T ,一个用来存储结果的 P P P  先 ...

  8. 计算矩阵的逆和行列式的值(高斯消元+LU分解)

    计算矩阵的逆 选主元的高斯消元法 朴素的高斯消元法是将矩阵A和单位矩阵放在一起,通过行操作(或者列操作)将A变为单位矩阵,这个时候单位矩阵就是矩阵A的逆矩阵.从上到下将A变为上三角矩阵的复杂度为O(n ...

  9. AC自动机 + 概率dp + 高斯消元 --- HDU 5955 or 2016年沈阳icpc H [AC自动机 + 概率dp + 高斯消元]详解

    题目链接 题目大意: 就是有NNN个人,每个人都会猜一个长度为LLL的只包含{1,2,3,4,5,6}\{1,2,3,4,5,6\}{1,2,3,4,5,6}的序列,现在裁判开始投掷骰子,并且把每次的 ...

最新文章

  1. Linux 操作系统原理 — 文件系统 — 管理与优化
  2. 《研磨设计模式》chap9 原型模式Prototype
  3. JavaScript实现Travelling Salesman算法(附完整源码)
  4. [JavaWeb-HTML]HTML标签_块标签
  5. python namespace unique_Python使用uuid库生成唯一标识ID
  6. windows和linux系统下测试端口连通性的命令
  7. .net core orm框架_轻量级高性能PHP框架ycroute
  8. 视频转为flv和图片
  9. php mail函数_php 发送邮件函数
  10. 使用Github官方提供的gitignore过滤Git提交的文件
  11. 微软4月补丁星期二修复119个漏洞,含2个0day
  12. iOS研发助手DoraemonKit技术实现之Crash查看
  13. dBeaver sql格式化配置-v1.5
  14. (二)NI采集卡应用学习:使用NI MAX创建测量任务及常见错误
  15. linux命令行大全第2版,Linux命令行大全(第2版)
  16. 【炫丽跑车win7主题】
  17. 钉钉视频下载地瓜网络钉钉视频下载器
  18. python dataframe 增加一行
  19. 【遇见Doris】Apache Doris 在京东广告平台的应用
  20. Simscape Multibody简介与入门(上) 准备工作

热门文章

  1. 几个常用SQL2000语句
  2. 知识图谱需要解决的问题
  3. [Leetcode][第257题][JAVA][二叉树的所有路径][BFS][DFS]
  4. 怎么检查计算机网络是连接,怎么检测网络打印机是否与电脑连接成功【检测方法】...
  5. 鸿蒙关键技术研究,华为鸿蒙 2.0 系统主题演讲公布,详细架构 9 月 11 日揭晓
  6. python启动多个进程_Python程序中的进程操作--—--开启多进程
  7. python股票网格交易法详解_干货 | 浅谈网格交易法
  8. uni app 调用网络打印机_uni-app 的使用体验总结
  9. dts数据库迁移工具_传统数据库迁移上云利器-ADAM
  10. python 异步 生产者 消费者_python 线程通信 生产者与消费者