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

题目来源

ACM-ICPC 2018 焦作赛区网络预赛

就是告诉你任意三个可以填的情况 推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【矩阵快速幂】的更多相关文章

  1. 2018 焦作网络赛 L Poor God Water ( AC自动机构造矩阵、BM求线性递推、手动构造矩阵、矩阵快速幂 )

    题目链接 题意 : 实际上可以转化一下题意 要求求出用三个不同元素的字符集例如 { 'A' .'B' .'C' } 构造出长度为 n 且不包含 AAA.BBB CCC.ACB BCA.CAC CBC ...

  2. 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 ...

  3. ACM-ICPC 2018 焦作赛区网络预赛 L Poor God Water(矩阵快速幂,BM)

    https://nanti.jisuanke.com/t/31721 题意 有肉,鱼,巧克力三种食物,有几种禁忌,对于连续的三个食物:1.这三个食物不能都相同:2.若三种食物都有的情况,巧克力不能在中 ...

  4. zoj 2974 Just Pour the Water矩阵快速幂

    Just Pour the Water Time Limit: 2 Seconds      Memory Limit: 65536 KB Shirly is a very clever girl. ...

  5. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/73982 ...

  6. 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 ...

  7. 2018焦作网络赛 - Poor God Water 一道水题的教训

    本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下坑点 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可 ...

  8. ACM-ICPC 2018 焦作网络赛

    题目顺序:A F G H I K L 做题链接 A. Magic Mirror 题意:判断 给出的 字符串 是否等于"jessie",需要判断大小写 题解:1.用stl库 tolo ...

  9. 2019-ACM-ICPC-沈阳区网络赛-K. Guanguan's Happy water-高斯消元+矩阵快速幂

    2019-ACM-ICPC-沈阳区网络赛-K. Guanguan's Happy water-高斯消元+矩阵快速幂 [Problem Description] 已知前\(2k\)个\(f(i)\),且 ...

随机推荐

  1. e556. 在程序中播放音频

    try { URL url = new URL("http://hostname/audio.au"); AudioClip ac = Applet.newAudioClip(ur ...

  2. (转)windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime

    执行 10000000 次, 耗时 2258,369 微秒     QueryPerformanceCounter 执行 10000000 次, 耗时 26,347 微秒    GetTickCoun ...

  3. Sql server中根据存储过程中的部分信息查找存储过程名称的方法【视图和Function】

    .查询的语句: select a.id,b.name,a.*,b.* from syscomments a join sysobjects b on a.id=b.id where b.xtype=' ...

  4. 【Java面试题】28 简述synchronized和java.util.concurrent.locks.Lock的异同 ?

    主要相同点:Lock能完成synchronized所实现的所有功能 主要不同点:Lock有比synchronized更精确的线程语义和更好的性能.synchronized会自动释放锁,而Lock一定要 ...

  5. win7在64位系统下编译openssl

    曾经在笔记本上配置过openssl-0.9.8g版本号,今天在公司的台式机上配置死活没配置成功.机器的系统是win7,64位.编译openssl-1.0.1e出现各种莫名的错误,最后无意中编译了1.0 ...

  6. C++ string(转)

    C++中string是标准库中一种容器,相当于保存元素类型为char的vector容器(自己理解),这个类提供了相当丰富的函数来完成对字符串操作,以及与C风格字符串之间转换,下面是对string一些总 ...

  7. C++primer中 CacheObj实现(非常有意思)

    //CacheObj.h #ifndef __CacheObj__ #define __CacheObj__ #include <iostream> #include <stdexc ...

  8. Unity 大版本更新之APK的下载与覆盖安装

    作为一个游戏开发者,更新这个技能是必不可少的!更新分为游戏内的更新,也就是所谓的资源热更包括AssetBundle更新和代码更新,代码其实也是所谓的二进制文件,在安卓上和普通资源文件毫无差异,然而在I ...

  9. Android开发之程序猿必需要懂得Android的重要设计理念2(5.20更新版)

    上篇文章介绍了Android开发的设计理念的一部分,并没有得到博友们的多大认可,仅仅看到了一位博友在以下留言期待下一篇文章的发表,为了这小小的唯一支持.我决定继续把后面的8个要点介绍一下,自己也潜心反 ...

  10. GIS-010-ArcGIS JS 三种查询模式(转)

    QueryTask.FindTask.IdentifyTask都是继承自ESRI.ArcGIS.Client.Tasks: 1.QueryTask:是一个进行空间和属性查询的功能类,它可以在某个地图服 ...