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. Object.create 以原对象为原型创建一个新对象

    Object.create = function(o){ var Fun = function(){}; Fun.prototype = o; return new Fun(); } var peo ...

  2. 8-html表格

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  3. windows查看端口被占用情况

    首先,使用cmd命令打开CMD命令窗口 使用下面的命令来查看某端口被占用的情况,以8035为例: netstat -ano|findstr " 结果如下图: 最后一列的6532为PID号,根 ...

  4. LeetCode 740. Delete and Earn

    原题链接在这里:https://leetcode.com/problems/delete-and-earn/ 题目: Given an array nums of integers, you can ...

  5. Python爬虫 | 多线程、多进程、协程

    对于操作系统来说,一个任务就是一个进程(Process),比如打开一个浏览器就是启动一个浏览器进程,打开一个记事本就启动了一个记事本进程,打开两个记事本就启动了两个记事本进程,打开一个Word就启动了 ...

  6. WinDbg 图形界面功能(四)

    二.工具栏 除了断点按钮在工具栏上的每个按钮相当于菜单命令. 每个按钮的效果的完整说明,请参阅相应的菜单命令的页. 在工具栏上的按钮具有以下效果. 按钮 描述 打开源文件为只读的文件. 等效于文件 | ...

  7. Redis的通用key操作

    这些操作跟具体的类型没有关系,而是跟key相关. 1.查询Redis中的key的名称: 所有key: 以my开头: 2.删除键: 3.判断某一个键是否存在: 4.重命名: 5.设置过期时间: 如果未设 ...

  8. The two of the oldest man need cheers

    At a company dinner, the drinking rule was that two colleagues of similar age clinked glasses of win ...

  9. 验证和交叉验证(Validation & Cross Validation)

    之前在<训练集,验证集,测试集(以及为什么要使用验证集?)(Training Set, Validation Set, Test Set)>一文中已经提过对模型进行验证(评估)的几种方式. ...

  10. 第03组 Alpha冲刺(1/4)

    队名:不等式方程组 组长博客 作业博客 团队项目进度 组员一:张逸杰(组长) 过去两天完成的任务: 文字/口头描述: 制定了初步的项目计划,并开始学习一些推荐.搜索类算法 GitHub签入纪录: 暂无 ...