Covering

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

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
题解:这个题目不是很好写  ,但是有很多人AC得特别快   大神的脚步完全跟不上
直接找规律    想公式  想了特别就都没有想出来
还是实验室有人使用dfs求了前面几个数的答案   然后使用循环求出去套出了规律
不过找到了规律  数据量也还是很大    10的18次方  
所以这里还是得使用矩阵快速幂    才行
 矩阵的算法   比赛中比较常见
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = ;
ll Matrixsize = , mod = int(1e9)+, n;
struct Matrix {
ll m[maxn][maxn];
Matrix(ll i = ) {
memset(m, , sizeof m);
if (i == )
for (ll I = ; I < Matrixsize; I++) m[I][I] = ;
}
Matrix operator * (const Matrix tmp) const {
Matrix ret;
long long x;
for(ll i= ; i<Matrixsize ; i++)
for(ll j= ; j<Matrixsize ; j++) {
x=;
for(ll k= ; k<Matrixsize ; k++)
x+=(m[i][k] * tmp.m[k][j] + mod) % mod;
ret.m[i][j] = int(x % mod);
}
return ret;
}
Matrix qpow(long long n) {
Matrix ret = , tmp = *this;
while (n > ) {
if (bool(n & )) ret = ret * tmp;
tmp = tmp * tmp;
n >>= ;
}
return ret;
}
}; int main() {
Matrix base1 = , base2 = ;
base1.m[][] = base1.m[][] = base1.m[][] = base1.m[][] = base1.m[][] = ;
base1.m[][] = -, base1.m[][] = , base2.m[][] = ;
base2.m[][] = , base2.m[][] = , base2.m[][] = ;
while(~scanf("%lld",&n)) printf("%lld\n",(base1.qpow(n)*base2).m[][]);
return ;
}

2017ACM/ICPC广西邀请赛 1004 Covering的更多相关文章

  1. 2017 ICPC 广西邀请赛1004 Covering

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

  2. 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering

    Problem Description Bob's school has a big playground, boys and girls always play games here after s ...

  3. 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)

    上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3 ...

  4. 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi

    Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...

  5. 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 ...

  6. 2017ACM/ICPC广西邀请赛-重现赛

    HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...

  7. HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序

    题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...

  8. 2017ACM/ICPC广西邀请赛-重现赛 1001 A Math Problem

    2017-08-31 16:48:00 writer:pprp 这个题比较容易,我用的是快速幂 写了一次就过了 题目如下: A Math Problem Time Limit: 2000/1000 M ...

  9. 2017ACM/ICPC广西邀请赛-重现赛1005 CS course

    2017-08-31 16:19:30 writer:pprp 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...

随机推荐

  1. 通过Python实现mysql查询数据库实例

    #coding:utf-8 ''' Created on 2017年10月25日 @author: li.liu ''' import pymysql db=pymysql.connect('loca ...

  2. 192-0070 Final project proposal

    Final project proposal192-00701 – Summary of your project.It is based on an existing game which is c ...

  3. MySQL命令操作(Linux平台)

    Linux shell 批量创建数据库/表 Shell 脚本如下: # create database and table HOST='localhost' PORT='3306' USER='roo ...

  4. Tensorflow细节-Tensorboard可视化-简介

    先搞点基础的 注意注意注意,这里虽然很基础,但是代码应注意: 1.从writer开始后边就错开了 2.writer后可以直接接writer.close,也就是说可以: writer = tf.summ ...

  5. php 常用操作数组函数

    我们有很多操作数组的元素,我们这一节先讲一些.在6.3里面我们会总结更多的数组常用函数.深圳dd马达 下面的几个主要是移动数组指针和压入弹出数组元素的和个函数. 函数 功能 array_shift 弹 ...

  6. [bzoj1008] 越狱

    Description 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱 数据 ...

  7. iview 的事件绑定

    iview 内的组件样式是不错,有时候我们想用它且绑定某个事件: 比如,我们使用了步骤条组件(Steps),然后绑定点击事件,实现每次点击某个步骤条内的step 就显示此step的具体信息, < ...

  8. Linux 磁盘格式化、检验、挂载

    分区完毕之后自然要进行文件系统的格式化.格式化命令mkfs(make file system)这个命令.这是个综合命令,它会去调用正确的文件系统格式化工具软件. 磁盘格式化 mkfs mke2fs m ...

  9. 刷题记录:[ASIS 2019]Unicorn shop

    目录 刷题记录:[ASIS 2019]Unicorn shop 一.涉及知识点 1.Unicode安全问题 刷题记录:[ASIS 2019]Unicorn shop 题目复现链接:https://bu ...

  10. solr 使用

    Solr安装 1:安装 Tomcat,解压缩即可. 2:解压 solr. 3:把 solr 下的dist目录solr-4.10.3.war部署到 Tomcat\webapps下(去掉版本号). 4:启 ...