焦作网络赛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)\),且 ...
随机推荐
- Spring 4 官方文档学习(十)数据访问之DAO支持
1.介绍 Spring 中 Data Access Object (DAO)支持 的目标是以一种一致的方式更简单的使用JDBC.Hibernate.JPA或JDO等数据访问技术.可以在前面说的几种数据 ...
- ubuntu下使用VI编辑文件必知的常用命令
进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi +n filename :打开文件,并将光标置于第n行首 vi + filename :打开文件,并将光标置于最后 ...
- 网络协议之bt---bt协议详解 DHT篇(下)
-------------------------author:pkf -------------------------------qq:1327706646 ------------------- ...
- resize2fs: Bad magic number in super-block while trying to open
I am trying to resize a logical volume on CentOS7 but am running into the following error: resize2fs ...
- 【Latex】数学公式排版
http://www.cnblogs.com/houkai/p/3399646.html 常用latex数学符号表 https://zh.wikipedia.org/wiki/Help:%E6%95% ...
- 如何创建 SVN 服务器,并搭建自己的 SVN 仓库
SVN是一个广泛使用的版本控制系统,在日常工作中有广泛的应用空间,比如文档管理,我们就可以搭建一个 SVN 仓库,日常需要归类保存的文档统统上传到仓库中,那如何创建 SVN 服务器, 又如何搭建 SV ...
- Java精选笔记_面向对象(包、访问控制、内存机制、垃圾回收机制)
包 包的定义与使用 专门用来存放类的,通常功能相同的类存放在相同的包中. 包的声明只能位于Java源文件的第一行 Java语言中的常用包 java.lang:包含Java语言的核心类,如String. ...
- Python 爬虫知识点
一.基础知识 1.HTML分析 2.urllib爬取 导入urilib包(Python3.5.2) 3.urllib保存网页 import urllib.requesturl = "http ...
- VS2015编译CURL7.54.0源码
2018.8.24找到一种新途径,运行curl-master\projects\generate.bat,然后curl-master\projects\Windows\VC14\curl-all.sl ...
- PyQt4滑块QSlider、标签QLabel
滑块部件由一个简单的操控杆构成,用户可以通过向前或向后滑动滑块来选择数据.这种选择数据的方式对一些特殊的任务来说比单纯的提供一个数据或使用spin box调整数据大小的方式要自然友好的多.而标签部件则 ...