2017ACM/ICPC广西邀请赛 1004 Covering
Covering
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total
Submission(s): 0 Accepted Submission(s): 0
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?
Each
test case only contains one positive integer n in a line.
1≤n≤1018
in a line.
2
5
矩阵的算法 比赛中比较常见
#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的更多相关文章
- 2017 ICPC 广西邀请赛1004 Covering
Covering Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering
Problem Description Bob's school has a big playground, boys and girls always play games here after s ...
- 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 ...
- HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序
题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...
- 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 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...
随机推荐
- DT资讯文章生成静态出现MySQL Error解决办法
今天有个朋友的DT系统生成静态出现 MySQL Query:SELECT * FROM [pre]article_21 WHERE status=3 and itemid<>516548 ...
- axios基本设置
- AST11103 Problem Solving
AST11103 Problem Solving with Programming SkillsAdditional Individual Assignment: Min-Game Programmi ...
- pycharm激活2018(终极解决办法)
1.将“0.0.0.0 account.jetbrains.com”中的内容添加到hosts文件中,hosts路径为:C:\Windows\System32\drivers\etc 2.打开http: ...
- oracle数据库登录和
首先引用百度云两个DLL文件 dbhelpher.DLL 和 Oracle.ManagedDataAccess.dll,加入配置文件sysdb文件 配置文件内容 < [DBMODE]MODE= ...
- 使用SpringBoot访问jsp页面
1 编写application.yml文件 spring: mvc: view: suffix: .jsp prefix: /jsp/ 2 创建Controller层 @Controller @Req ...
- solidworks 学习 (一)
螺丝刀建模
- Java Web 项目的文件/文件夹上传下载
需求: 支持大文件批量上传(20G)和下载,同时需要保证上传期间用户电脑不出现卡死等体验: 内网百兆网络上传速度为12MB/S 服务器内存占用低 支持文件夹上传,文件夹中的文件数量达到1万个以上,且包 ...
- 堆内存腐败异常(STATUS_HEAP_CORRUPTION---0xC0000374)
什么是内存腐败 当堆内存位置的内容由于编程行为而被修改,超出了原始程序构造的意图时,计算机程序就会发生内存腐败,也可以叫内存破坏:这被称为违反内存安全.内存腐败的最可能原因是编程错误.当腐败的内存内容 ...
- Windows是如何将64位Ntdll映射到32位进程的---转自简书
今天我们探索一个问题: 64位的ntdll是如何被加载到WoW64下的32位进程?今天的旅程将会带领我们进入到Windows内核逻辑中的未知领域,我们将会发现32位进程的内存地址空间是如何被初始化的. ...