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. 10. vue-router命名路由

    命名路由的配置规则 为了更加方便的表示路由的路径,可以给路由规则起一个别名, 即为"命名路由". const router = new VueRouter ({ routes: [ ...

  2. hexo与github page搭建博客

    安装 npm i hexo-cli -g hexo init blog cd blog npm install hexo server 发布hexo到github page npm i hexo-de ...

  3. redis提权

    介绍:Redis是一个开源的使用ANSI C语言编写.遵守BSD协议.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.它通常被称为数据结构服务器,因为值(va ...

  4. JS判断某变量是否为某数组中的一个值的3种方法

    1.正则表达式 js 中判断某个元素是否存在于某个 js 数组中,相当于 PHP 语言中的 in_array 函数. 1 Array.prototype.in_array = function (e) ...

  5. python接口自动化—封装获取常量的类

    背景: 一.执行case的过程: 首先需要,我们能够通过excel获取单元格的内容.获取内容时,首先需要知道获取的数据是哪一行的,这行数据中需要拿那些参数,比如case 名称.请求url.请求方式.h ...

  6. CSPS_109

    T1 状压+位运算解决 T2 打完暴力后感到了迷茫.. 不过看这张表里1的数目占了一半之多,应该合法情况挺多的 拿出了从未用过的srand(time(0)); 结果撞上正解了(笑)(rp--) 现在$ ...

  7. 73: luogu 2014 树形dp

    $des$ 在大学里每个学生,为了达到一定的学分,必须从很多课程里选择一些课程来学习,在课程里有些课程必须在某些课程之前学习,如高等数学总是在其它课程之前学习.现在有N门功课,每门课有个学分,每门课有 ...

  8. 我的Android前生今世之缘-学习经验-安卓入门教程(六)

    关注我,每天都有优质技术文章推送,工作,学习累了的时候放松一下自己. 本篇文章同步微信公众号 欢迎大家关注我的微信公众号:「醉翁猫咪」 据我所知,网上教学资料一堆一堆的,那么还有很多人说,如何学习? ...

  9. javascript 中的方法注入

    js 中的方法注入 java中很多框架支持 apo 的注入, js中也可以类似的进行实现 主要是通过扩展js中方法的老祖 Function 对象来进行实现. Function.prototype.af ...

  10. Sybase数据库连接配置

    简介 1984年,Mark B. Hiffman和Robert Epstern创建了Sybase公司,并在1987年推出了Sybase数据库产品.SYBASE主要有三种版本,一是UNIX操作系统下运行 ...