焦作网络赛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)\),且 ...
随机推荐
- java中Scanner的nextLine()和next()的区别
首先,next()一定要读取到有效字符后才可以结束输入,对输入有效字符之前遇到的空格键.Tab键或Enter键等结束符,next()方法会自动将其去掉,只有在输入有效字符之后,next()方法才将其后 ...
- 重载 CreateParams 方法[1]: 从一个例子开始(取消窗口最大化、最小化按钮的三种方法)
方法1: 使用 TForm 的 BorderIcons 属性 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, C ...
- Socket网络编程精华篇
几个和Socket编程紧密相关的概念: TCP/IP层次模型 当然这里我们只讨论重要的四层 01,应用层(Application):应用层是个很广泛的概念,有一些基本相同的系统级TCP/IP应用以及应 ...
- 搭建 FTP 文件服务vsftpd
安装并启动 FTP 服务 安装 VSFTPD 使用 yum 安装 vsftpd: yum install vsftpd -y vsftpd 是在 Linux 上被广泛使用的 FTP 服务器,根据其[官 ...
- brew faq:call ISHELL_GetJulianDate always return 1980 1 6
假设你当时系统的时间为20130804000000,那么如果你将系统的时间改为20140104000000,那么ISHELL_GetJulianDate 将返回20140104000000. 但如果 ...
- [大数据] zookeeper 安装和配置
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的功 ...
- mysql中根据一个字段相同记录写递增序号,如序号结果,如何实现?
mysql中根据一个字段相同记录写递增序号,如序号结果,如何实现? mysql中实现方式如下: select merchantId, NameCn, send_date, deliver_name ...
- kafka的相关操作脚本
总结最近用到的kafka相关命令和脚本. 1.创建Topic./kafka-topics.sh --zookeeper cc13-141:2182 --topic mytopic --replicat ...
- Python tips: 什么是*args和**kwargs?
推荐查看:https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00137473844 ...
- Zookeeper(三)-- JAVA原生API
一.前提 jar包:zookeeper-3.4.9.jar,slf4j-api-1.6.1.jar,slf4j-log4j12-1.6.1.jar,log4j-1.2.15.jar 二.Demo pa ...