2017ACM/ICPC广西邀请赛-重现赛 1004.Covering
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
题目大意:用1×2和2×1的矩形填满N×4的方格,求方案数
解题报告:打表发现规律:\(f_n=f_{n-1}+5*f_{n-2}+f_{n-3}-f_{n-4}\)
然后矩阵快速幂求解即可:
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
const int N=5,mod=1000000007;
struct mat{
ll a[N][N];
mat(){memset(a,0,sizeof(a));}
mat operator *(const mat p)const{
mat tmp;
for(int i=1;i<N;i++)
for(int j=1;j<N;j++)
for(int k=1;k<N;k++){
tmp.a[i][j]+=(a[i][k]*p.a[k][j])%mod;
tmp.a[i][j]=((tmp.a[i][j]%mod)+mod)%mod;
}
return tmp;
}
};
ll n;int f[5];
void work()
{
if(n<=4){
printf("%d\n",f[n]);
return ;
}
mat S,T;
for(int i=1;i<=4;i++)S.a[1][i]=f[5-i];
T.a[1][1]=1;T.a[2][1]=5;T.a[3][1]=1;T.a[4][1]=-1;
for(int i=2;i<=4;i++)T.a[i-1][i]=1;
n-=4;
while(n){
if(n&1)S=S*T;
T=T*T;n>>=1;
}
printf("%lld\n",S.a[1][1]);
}
int main()
{
f[1]=1;f[2]=5;f[3]=11;f[4]=36;
while(~scanf("%lld",&n))work();
return 0;
}
2017ACM/ICPC广西邀请赛-重现赛 1004.Covering的更多相关文章
- 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...
- 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi
Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...
- 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree
Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...
- 2017ACM/ICPC广西邀请赛-重现赛
HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...
- 2017ACM/ICPC广西邀请赛-重现赛 1001 A Math Problem
2017-08-31 16:48:00 writer:pprp 这个题比较容易,我用的是快速幂 写了一次就过了 题目如下: A Math Problem Time Limit: 2000/1000 M ...
- 2017ACM/ICPC广西邀请赛-重现赛1005 CS course
2017-08-31 16:19:30 writer:pprp 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...
- 2017ACM/ICPC广西邀请赛 1004 Covering
Covering Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序
题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...
- 2017ACM/ICPC广西邀请赛
A.A Math Problem #include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll ...
随机推荐
- CocoaPods 基础知识--------安装 及 使用第三方库
极客学院:http://www.jikexueyuan.com/course/2665_2.html?ss=1
- scrapy 数据存储mysql
#spider.pyfrom scrapy.linkextractors import LinkExtractor from scrapy.spiders import CrawlSpider, Ru ...
- MySql数据库的常用命令
1.连接Mysql 连接本地的mysql数据库 : mysql -u root -p (回车之后会提示输入密码) 连接远程主机的mysql数据库 : 假设远程主机的IP为:110.110.1 ...
- prop attr 到底哪里不一样?
好吧 首先承认错误 说好的每天进行一次只是总结 但是我没坚持住 准确的来说 我并没有每天会学到了东西 但是 我一直在持续努力着 以后应该不会每天都写 但是自己觉得有用的 或者想加强记忆的 可 ...
- mysql数据库的三范式的设计与理解
一般的数据库设计都需要满足三范式,这是最基本的要求的,最高达到6NF,但是一般情况下3NF达到了就可以 一:1NF一范式的理解: 1NF是关系型数据库中的最基本要求,就是要求记录的属性是原子性,不可分 ...
- Python内置函数(52)——getattr
英文文档: getattr(object, name[, default]) Return the value of the named attribute of object. name must ...
- SpringCloud的服务网关zuul
演示如何使用api网关屏蔽各服务来源 一.概念和定义 1.zuul最终还是使用Ribbon的,顺便测试一下Hystrix断路保护2.zuul也是一个EurekaClient,访问服务注册中心,获取元数 ...
- matlab等高线绘制
参考代码: figure;// Figure建立新的图形 z=double(z); x=1:length(z); y=x; [X2,Y2]=meshgrid(x,y); subplot(121); [ ...
- 敏捷项目需求拆解&发现用户故事
需求文档和敏捷中的Epic,User Story, Task之间是什么关系以及如何将需求文档转换成敏捷方式的描述,指导开发人员. 一直是很多公司团队比较困扰的问题,那么最近笔者为了解决这些问题,上了一 ...
- java stream 原理
java stream 原理 需求 从"Apple" "Bug" "ABC" "Dog"中选出以A开头的名字,然后从中选 ...