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. Ubuntu安装微信,解决deepin“版本过低”或NO_PUBKEY问题

    在搜索引擎搜索Ubuntu安装微信,最多的结果是通过deepin安装 但是里面使用的deepin-for-ubuntu 安装之后微信扫码会提示版本过低 直接安装deepin.com.wechat_2. ...

  2. 第二阶段:2.商业需求分析及BRD:4.产品需求分析总结

    产品的需求筛选 战略定位要考虑公司的战略问题.产品定位要分阶段,各个阶段的需求不同. 其实现在需求分析跟筛选都是非常快的. 不把需要当成需求,意思就是不要用户说需要什么就是什么,用户需要引导. 先分类 ...

  3. saltstack操作

    使用分组 修改minon的ID,做一个标识 [root@node2 ~]# vim /etc/salt/minionmaster: 172.25.254.130 id: web1 #node2[roo ...

  4. leetcode.383赎金信

    给定一个赎金信 (ransom) 字符串和一个杂志(magazine)字符串,判断第一个字符串ransom能不能由第二个字符串magazines里面的字符构成.如果可以构成,返回 true :否则返回 ...

  5. Windows远程桌面管理--功能强大的远程批量管理工具【转】

    曾经,我想着要是有一款绿色小巧,功能实用的远程桌面管理工具,其界面简洁,操作便捷,能够同时远程操作多台服务器,并且多台服务器间可以自由切换,适用于网站管理人员使用的工具该有多好,苍天不负有心人,终于出 ...

  6. MyBatis原理-延迟加载,一级缓存,二级缓存设置

    一.延迟加载 resultMap中的association和collection标签具有延迟加载的功能. 延迟加载的意思是说,在关联查询时,利用延迟加载,先加载主信息.使用关联信息时再去加载关联信息. ...

  7. 你的IDEA过期了?跃哥四大招帮你稳住

    作者:Dimple Solgan:当你的才华还无法撑起你的野心时候,那应该静下心来好好学习 前天晚上在群里风风火火组建了两个学习小组,一个是面向Java初学,一个是面向Python初学,把我搞的兴奋不 ...

  8. linux中的ldd命令简介

    转载自:http://blog.csdn.net/stpeace/article/details/47069215 在linux中, 有些命令是大家通用的, 比如ls, rm, mv, cp等等, 这 ...

  9. 基于Spring封装的Javamail实现邮件发送

    1.依赖 <dependency> <groupId>org.springframework</groupId> <artifactId>spring- ...

  10. echarts设置柱状图颜色渐变及柱状图粗细大小

    series: [ { name: '值', type: 'bar', stack: '总量', //设置柱状图大小 barWidth : 20, //设置柱状图渐变颜色 itemStyle: { n ...