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. 机器学习- Numpy基础 吐血整理

    Numpy是专门为数据科学或者数据处理相关的需求设计的一个高效的组件.听起来是不是挺绕口的,其实简单来说就2个方面,一是Numpy是专门处理数据的,二是Numpy在处理数据方面很牛逼(肯定比Pytho ...

  2. Flask框架知识点整合

    Flask 0.Flask简介 Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收ht ...

  3. java中如何自动获取电脑的ip地址

    String ip=InetAddress.getLocalHost().getHostAddress().toString(); 可以写一个main方法测试一下.

  4. vue学习笔记(四)事件处理器

    前言 在上一章vue学习笔记(三)class和style绑定的内容中,我们学习了如何在vue中绑定class和style,介绍了常用的绑定方法,class的数组绑定和对象绑定以及style的数组绑定和 ...

  5. 洛谷$1541$ 乌龟棋 线性$DP$

    Luogu   CH Sol f[i]表示走到第i个格子时获得的最大分数 发现转移与各个爬行卡片的数量有关,一共只有4种卡片 所以就把这四种卡片的已使用张数也放进状态,f[i][a][b][c][d] ...

  6. 1094 谷歌的招聘 (20 分)C语言

    2004 年 7 月,谷歌在硅谷的 101 号公路边竖立了一块巨大的广告牌(如下图)用于招聘.内容超级简单,就是一个以 .com 结尾的网址,而前面的网址是一个 10 位素数,这个素数是自然常数 e ...

  7. Java江湖之设计模式

    Java江湖之设计模式 ps:最近在学习设计模式,感觉这个是个装逼神器呀,就跟武功一样.     某日,senior同学看见rookie同学在练功.     问,"你练得什么武功?" ...

  8. docker操作

    Redis docker run -itd --name myredis -v /dockerdata/redis/config/redis.conf:/etc/redis/redis.conf  - ...

  9. Antd组件库使用方法

    零.介绍: Ant design,是阿里巴巴的蚂蚁金服公司设计的一套适应用于web端和移动端网页的Ui组件库,组件好看,非常适合React框架使用. 官网:https://ant.design/ind ...

  10. Spring循环依赖的解决

    ## Spring循环依赖的解决 ### 什么是循环依赖 循环依赖,是依赖关系形成了一个圆环.比如:A对象有一个属性B,那么这时候我们称之为A依赖B,如果这时候B对象里面有一个属性A.那么这时候A和B ...