焦作网络赛L-Poor God Water【矩阵快速幂】
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous.
Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 33 continuous hours when he eats only one kind of food, he will be unhappy. Besides, if there are 33 continuous hours when he eats all kinds of those, with chocolate at the middle hour, it will be dangerous. Moreover, if there are 33 continuous hours when he eats meat or fish at the middle hour, with chocolate at other two hours, it will also be dangerous.
Now, you are the doctor. Can you find out how many different kinds of diet that can make God Water happy and safe during NN hours? Two kinds of diet are considered the same if they share the same kind of food at the same hour. The answer may be very large, so you only need to give out the answer module 10000000071000000007.
Input
The fist line puts an integer TT that shows the number of test cases. (T \le 1000T≤1000)
Each of the next TT lines contains an integer NN that shows the number of hours. (1 \le N \le 10^{10}1≤N≤1010)
Output
For each test case, output a single line containing the answer.
样例输入复制
3
3
4
15
样例输出复制
20
46
435170
题目来源
就是告诉你任意三个可以填的情况 推n个的时候有多少种情况
像这种前一种情况可以推后一种情况的 而且n还这么大的 可以考虑矩阵快速幂
建一个9*9的矩阵 每一种表示一个2位可填的状态 行表示前两个 列表示这前两个可推出的后两个
比如MCC是一种可行的 就在MC这行对应CC这列写1
快速幂可得所有情况
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<set>
#include<stack>
//#include<bits/stdc++.h>
#define inf 0x7f7f7f7f7f7f7f7f
using namespace std;
typedef long long LL; const LL mod = 1e9 + ;
int t;
LL n; struct Matrix {
LL a[][] = {{}};
Matrix operator * (const Matrix &b)const {
Matrix ret;
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
ret.a[i][j] = ;
for (int k = ; k <= ; k++) {
ret.a[i][j] += a[i][k] * b.a[k][j];
ret.a[i][j] %= mod;
}
}
}
return ret;
}
}; Matrix ksm(Matrix a, LL x)
{
Matrix ret, k;
k = a;
ret = a;
x--;
while (x) {
if (x & ) {
ret = ret * k;
}
x >>= ;
k = k * k;
}
return ret;
} int main()
{
cin >> t;
while (t--) {
cin >> n;
if (n == ) {
cout << << endl;
}
else if (n == ) {
cout << << endl;
}
else {
Matrix m;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = ;
m.a[][] = m.a[][] = m.a[][] = ;
m = ksm(m, n - );
LL f[] = { , , , , , , , , , };
LL ans[] = { };
for (int i = ; i <= ; i++) {
for (int j = ; j <= ; j++) {
ans[i] += m.a[i][j] * f[j];
ans[i] %= mod;
}
} LL res = ;
for (int i = ; i <= ; i++) {
res = (res + ans[i]) % mod;
}
cout << res << endl;
}
}
return ;
}
焦作网络赛L-Poor God Water【矩阵快速幂】的更多相关文章
- 2018 焦作网络赛 L Poor God Water ( AC自动机构造矩阵、BM求线性递推、手动构造矩阵、矩阵快速幂 )
题目链接 题意 : 实际上可以转化一下题意 要求求出用三个不同元素的字符集例如 { 'A' .'B' .'C' } 构造出长度为 n 且不包含 AAA.BBB CCC.ACB BCA.CAC CBC ...
- ACM-ICPC 2018 焦作赛区网络预赛 L:Poor God Water(矩阵快速幂)
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- ACM-ICPC 2018 焦作赛区网络预赛 L Poor God Water(矩阵快速幂,BM)
https://nanti.jisuanke.com/t/31721 题意 有肉,鱼,巧克力三种食物,有几种禁忌,对于连续的三个食物:1.这三个食物不能都相同:2.若三种食物都有的情况,巧克力不能在中 ...
- zoj 2974 Just Pour the Water矩阵快速幂
Just Pour the Water Time Limit: 2 Seconds Memory Limit: 65536 KB Shirly is a very clever girl. ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/73982 ...
- ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- 2018焦作网络赛 - Poor God Water 一道水题的教训
本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下坑点 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可 ...
- ACM-ICPC 2018 焦作网络赛
题目顺序:A F G H I K L 做题链接 A. Magic Mirror 题意:判断 给出的 字符串 是否等于"jessie",需要判断大小写 题解:1.用stl库 tolo ...
- 2019-ACM-ICPC-沈阳区网络赛-K. Guanguan's Happy water-高斯消元+矩阵快速幂
2019-ACM-ICPC-沈阳区网络赛-K. Guanguan's Happy water-高斯消元+矩阵快速幂 [Problem Description] 已知前\(2k\)个\(f(i)\),且 ...
随机推荐
- Understanding the difficulty of training deep feedforward neural networks
本文作者为:Xavier Glorot与Yoshua Bengio. 本文干了点什么呢? 第一步:探索了不同的激活函数对网络的影响(包括:sigmoid函数,双曲正切函数和softsign y = x ...
- css -- 背景图片自适应屏幕大小
由于<body>标签的图片不能够拉伸, 解决办法: 1.图片不够大,又background属性不能拉伸图片: 2.只能用个div,把其z-index值设为负,并使这个div大小为整个bod ...
- SQL 模糊查询LIKE concat用法
concat用来拼接查询的字符串,如下代码所示 SELECT * FROM deployment WHERE name LIKE concat(concat('%',#{queryMessage}), ...
- Oracle Net Manager 服务命名配置以及用PL/SQL 登陆数据库
我们知道,要连接一个数据库需要知道四个参数: 1. 登陆用户名:user: 2. 登录密码:password: 3. 存放数据库的服务器地址(server_ip)和端口(server_port): 4 ...
- svn merge和branch分析
[转载] 使用svn几年了,一直对分支和合并敬而远之,一来是因为分支的管理不该我操心,二来即使涉及到分支的管理,也不敢贸然使用合并功能,生怕合并出了问题对团队造成不良影响,最主要的原因是,自己对分支的 ...
- Ubuntu 12.04/13.04 安装 Oracle11gR2:该笔记已经陈旧!请参考后续的笔记
注意点: 在 ubuntu的 /bin 下建立以下几个基本命令的链接: basename awk sh->bash | sh -> ksh 安装以下几个必须的包: binutils bui ...
- SVN版控系统的安装和使用
SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.互联网上很多版本控制服务已从CVS迁移到Subversion ...
- VC++ :实现简单的文件拖放(Drag and Drop)功能
1) VC++ 6.0 新建一个基于对话框的MFC的工程,取名MfcDropFiles: 2) 去除默认的控件,包括确定/取消按钮,以及一个静态文本: 3) 在对话框空白区域拖放一个ListBox控件 ...
- mysqlbinlog工具的作用是什么呢,如何将binary log转换为文本格式?
需求描述: 今天在看mysqlbinlog这个工具,就在想这个工具到底是干嘛的呢,在mysql数据库中, binary log中记录了数据库内容的变化或者说修改,这些修改是以二进制的方式存储到 bin ...
- 开源 免费 java CMS - FreeCMS1.9 移动APP生成网站列表数据
项目地址:http://www.freeteam.cn/ 生成网站列表数据 提取同意移动APP訪问的网站列表,生成json数据到/mobile/index.html页面. 从左側管理菜单点击生成网站列 ...