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. 举例理解Hibernate的三种状态(转)

    转自:https://blog.csdn.net/yiguang_820/article/details/79073152 初学Hibernate,了解到Hibernate有三种状态:transien ...

  2. 我们基于kaldi开发的嵌入式语音识别系统升级成深度学习啦

    先前的文章<三个小白是如何在三个月内搭一个基于kaldi的嵌入式在线语音识别系统的>说我们花了不到三个月的时间搭了一个基于kaldi的嵌入式语音识别系统,不过它是基于传统的GMM-HMM的 ...

  3. javascript DOM 编程艺术 札记1

    一个重要观点 DOM 是指 文档对象模型,它对应浏览器实际认知的东西.html 文本本身和 html 加载到浏览器中显示的东西并不是完全一致的,后者就是 DOM 节点树,它是浏览器实际认知的东西.一个 ...

  4. CentOS 下 git 401 Unauthorized while accessing 问题解决

    The requested URL returned error: 401 Unauthorized while accessing 这个一般是旧版git的问题,需要安装新版的.CentOS 想下载最 ...

  5. Spring Boot (5) 整合 RabbitMQ

    一.前言 RabbitMQ是实现了AMQP(高级消息队列协议)的开源消息中间件,RabbitMQ服务器是用Erlang(面向并发的编程语言)编写的. RabbitMQ官网下载地址:https://ww ...

  6. 20191024-3 互评Alpha阶段作品

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9860 本组对构建之法组评价的博客链接:https://www.cnblog ...

  7. 深度探索c++对象模型阅读笔记图

  8. Okhttp解析—Okhttp概览

    Okhttp解析-Okhttp概览 Okhttp作为目前Android使用最为广泛的网络框架之一,我们有必要去深入了解一下,本文是Okhttp解析的第一篇,主要是从宏观上认识Okhttp整个架构是如何 ...

  9. 现代主流框架路由原理 hash、history的底层原理

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. JS中常见的几种继承方法

    1.原型链继承 // 1.原型链继承 /* 缺点:所有属性被共享,而且不能传递参数 */ function Person(name,age){ this.name = name this.age = ...