Covering

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

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

题意:4xn的地面,用1x2或者2x1的地毯自由组合铺满,有几种方案(答案mod 1e9+7)

解题思路:(草稿纸冲冲冲)

                

有了递推式,矩阵快速幂就好了

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 0X3f3f3f3f
const ll MAXN = ;
const ll mod = 1e9 + ;
//矩阵的大小 模数
ll n;
struct MAT
{
ll mat[MAXN][MAXN];
MAT operator*(const MAT &a) const
{
//重载矩阵乘法
MAT b;
memset(b.mat, , sizeof(b.mat));
for (int i = ; i < MAXN; i++)
{
for (int j = ; j < MAXN; j++)
{
for (int k = ; k < MAXN; k++)
b.mat[i][j] = (b.mat[i][j] + mat[i][k] * a.mat[k][j]);
b.mat[i][j] += mod;
b.mat[i][j] %= mod;
}
}
return b;
}
} start, ans;
MAT Mqpow(MAT base, ll b)
{
MAT r;
memset(r.mat, , sizeof(r.mat));
r.mat[][] = , r.mat[][] = , r.mat[][] = , r.mat[][] = ;
//初始状态
while (b)
{
if (b & )
r = base * r;
base = base * base;
b >>= ;
}
return r;
}
int main()
{ start.mat[][] = , start.mat[][] = , start.mat[][] = , start.mat[][] = ;
start.mat[][] = , start.mat[][] = , start.mat[][] = , start.mat[][] = ;
start.mat[][] = , start.mat[][] = , start.mat[][] = , start.mat[][] = ;
start.mat[][] = -, start.mat[][] = , start.mat[][] = , start.mat[][] = ;
//建立转移矩阵
ll f[] = {, , , , };
while (~scanf("%lld", &n))
{
if (n <= )
printf("%lld\n", f[n] % mod);
else
printf("%lld\n", Mqpow(start, n - ).mat[][]);
}
return ;
}

HDU-6185-Covering(推递推式+矩阵快速幂)的更多相关文章

  1. HDU 2842 Chinese Rings( 递推关系式 + 矩阵快速幂 )

    链接:传送门 题意:解 N 连环最少步数 % 200907 思路:对于 N 连环来说,解 N 连环首先得先解 N-2 连环然后接着解第 N 个环,然后再将前面 N-2 个环放到棍子上,然后 N 连环问 ...

  2. HDU - 2604 Queuing(递推式+矩阵快速幂)

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

  3. hdu 5950 Recursive sequence 递推式 矩阵快速幂

    题目链接 题意 给定\(c_0,c_1,求c_n(c_0,c_1,n\lt 2^{31})\),递推公式为 \[c_i=c_{i-1}+2c_{i-2}+i^4\] 思路 参考 将递推式改写\[\be ...

  4. HDU5950 Recursive sequence 非线性递推式 矩阵快速幂

    题目传送门 题目描述:给出一个数列的第一项和第二项,计算第n项. 递推式是 f(n)=f(n-1)+2*f(n-2)+n^4. 由于n很大,所以肯定是矩阵快速幂的题目,但是矩阵快速幂只能解决线性的问题 ...

  5. [题解][SHOI2013]超级跳马 动态规划/递推式/矩阵快速幂优化

    这道题... 让我见识了纪中的强大 这道题是来纪中第二天(7.2)做的,这么晚写题解是因为 我去学矩阵乘法啦啦啦啦啦对矩阵乘法一窍不通的童鞋戳链接啦 层层递推会TLE,正解矩阵快速幂 首先题意就是给你 ...

  6. hdu 5895 Mathematician QSC 指数循环节+矩阵快速幂

    Mathematician QSC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  7. hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!

    http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE,  更重要的是找出规律后,O(n)递推也过不了,TLE,一定 ...

  8. HDU 2276 Kiki & Little Kiki 2( 矩阵快速幂 + 循环同构矩阵 )

    蒟蒻的我还需深入学习 链接:传送门 题意:给出一个长度为 n,n 不超过100的 01 串 s ,每当一个数字左侧为 1 时( 0的左侧是 n-1 ),这个数字就会发生改变,整个串改变一次需要 1s ...

  9. HDU 1757 A Simple Math Problem(矩阵快速幂)

    题目链接 题意 :给你m和k, 让你求f(k)%m.如果k<10,f(k) = k,否则 f(k) = a0 * f(k-1) + a1 * f(k-2) + a2 * f(k-3) + …… ...

随机推荐

  1. [wireshark] ip filter

    查ip 时,使用 ip==10.224.37.18 发现无效 使用 ip.dst, 查到了 Match destination: ip.dst == x.x.x.x Match source: ip. ...

  2. 第二阶段:4.商业需求文档MRD:1.PRD-产品功能列表

    这就是对功能清单的梳理已经优先级筛选

  3. 面试必问之 ConcurrentHashMap 线程安全的具体实现方式

    作者:炸鸡可乐 原文出处:www.pzblog.cn 一.摘要 在之前的集合文章中,我们了解到 HashMap 在多线程环境下操作可能会导致程序死循环的线上故障! 既然在多线程环境下不能使用 Hash ...

  4. java中发送http请求的方法

    package org.jeecgframework.test.demo; import java.io.BufferedReader; import java.io.FileOutputStream ...

  5. 牛客训练赛55 E 树

    很妙的一个树形DP问题,简单考虑了一下就过了 https://ac.nowcoder.com/acm/contest/2927/E 主要就是推公式(公式有点长呀) 大概就是这样,其实挺简单的. #in ...

  6. Python socket套接字通信

    一.什么是socket? socket是一个模块, 又称套接字,用来封装 互联网协议(应用层以下的层). 二.为什么要有socket? socket可以实现互联网协议 应用层以下的层 的工作,提高开发 ...

  7. Markdown破解及汉化

    首先,附上用到的资源链接: 链接:https://pan.baidu.com/s/1ULvvCPcCv_P3KyD9ajXUjQ 提取码:5fkb 第一步 直接解压就可以,解压后运行该程序,会出现下图 ...

  8. 机器学习之路--Python

    常用数据结构 1.list 列表 有序集合 classmates = ['Michael', 'Bob', 'Tracy'] len(classmates) classmates[0] len(cla ...

  9. MySQL之插入数据(添加数据)-INSERT

    基本语法: INSERT 语句有两种语法形式,分别是 INSERT…VALUES 语句和 INSERT…SET 语句. 1.INSERT...VLAUES语句 INSERT VLAUES的语法格式如下 ...

  10. Linux环境下详细讲解部署MySQL5.7版本

    说明: 在本人写作这篇安装MySQL文章时,虽然MySQL已经发布到8.0.17版本,但对于行业来说,主力版本依然是5.7版本.目前在Linux环境默认安装时,大部分已经默认安装到8版本了,所以本人特 ...