题意

题目链接

Sol

直接矩阵快速幂

推出来的矩阵应该长这样

\begin{equation*}
\begin{bmatrix}
1&1&1&1&1&1\\
1 & 0&0&0&0&0\\
0 & 0&1&3&3&1\\
0 & 0&0&1&2&1\\
0 & 0&0&0&1&1\\
0 & 0&0&0&0&1\\
\end{bmatrix}^{i - 1}*
\begin{bmatrix}
F_{1}\\
F_0\\
1\\
1\\
1\\
1
\end{bmatrix}=
\begin{bmatrix}
1&1&1&1&1&1\\
1 & 0&0&0&0&0\\
0 & 0&1&3&3&1\\
0 & 0&0&1&2&1\\
0 & 0&0&0&1&1\\
0 & 0&0&0&0&1\\
\end{bmatrix}*
\begin{bmatrix}
F_{i - 1}\\
F_{i - 2}\\
i^3\\
i^2\\
i\\
1
\end{bmatrix}=
\begin{bmatrix}
F_{i}\\
F_{i - 1}\\
(i + 1)^3\\
(i + 1)^2\\
i + 1\\
1
\end{bmatrix}
\end{equation*}

#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define LL long long
//#define int long long
using namespace std;
const int mod = 1e9 + ;
inline LL read() {
char c = getchar(); LL x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int T;
LL N;
struct Matrix {
LL a[][], N;
Matrix() {
N = ;
memset(a, , sizeof(a));
}
Matrix operator * (const Matrix &rhs) const {
Matrix ans;
for(int k = ; k <= N; k++)
for(int i = ; i <= N; i++)
for(int j = ; j <= N; j++)
(ans.a[i][j] += (1ll * a[i][k] * rhs.a[k][j]) % mod) %= mod;
return ans;
}
};
Matrix fp(Matrix a, LL p) {
Matrix base;
// printf("%d", base.a[0][1]);
for(int i = ; i <= ; i++) base.a[i][i] = ;
while(p) {
if(p & ) base = base * a;
a = a * a; p >>= ;
}
return base;
}
const LL GG[][] = {
{, , , , , , },
{, , , , , , },
{, , , , , , },
{, , , , , , },
{, , , , , , },
{, , , , , , },
{, , , , , , }
};
int main() {
T = read();
while(T--) {
N = read();
if(N == ) {puts(""); continue;}
if(N == ) {puts(""); continue;}
Matrix M;
memcpy(M.a, GG, sizeof(M.a));
Matrix ans = fp(M, N - );
LL out = ;
(out += ans.a[][] * ) %= mod;
(out += ans.a[][] * ) %= mod;
(out += ans.a[][] * ) %= mod;
(out += ans.a[][] * ) %= mod;
(out += ans.a[][] * ) %= mod;
(out += ans.a[][]) %= mod;
printf("%lld\n", out % mod);
}
return ;
}
/*
5
4
1
2
3
100
*/

2018年湘潭大学程序设计竞赛G又见斐波那契(矩阵快速幂)的更多相关文章

  1. 2018年湘潭大学程序设计竞赛G又见斐波那契

    链接:https://www.nowcoder.com/acm/contest/105/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  2. 2017中国大学生程序设计竞赛 - 女生专场 Happy Necklace(递推+矩阵快速幂)

    Happy Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  3. 2018年湘潭大学程序设计竞赛 G- 又见斐波那契

    推一推矩阵直接快速幂. #include<bits/stdc++.h> #define LL long long #define pii pair<int,int> #defi ...

  4. 牛客网-2018年湘潭大学程序设计竞赛-F

    题目链接:https://www.nowcoder.com/acm/contest/105/F 解题思路:这道题第一眼直接思路就是搜索,但想了半天没想到有什么好办法搜,然后就转成最短路写了, 因为多入 ...

  5. 2018年湘潭大学程序设计竞赛 H统计颜色

    链接:https://www.nowcoder.com/acm/contest/105/H来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  6. 2018年湘潭大学程序设计竞赛 F - maze

    把点抽出来 跑个最短路就好啦. #include<bits/stdc++.h> #define LL long long #define pii pair<int,int> # ...

  7. 2018年湘潭大学程序设计竞赛 E 吃货

    题目描述 作为一个标准的吃货,mostshy又打算去联建商业街觅食了.混迹于商业街已久,mostshy已经知道了商业街的所有美食与其价格,而且他给每种美食都赋予了一个美味度,美味度越高表示他越喜爱这种 ...

  8. 2018年湘潭大学程序设计竞赛 Fibonacci进制

    Fibonacci数是非常有名的一个数列,它的公式为 f(n)=f(n-1)+f(n-2),f(0)=1,f(1)=2.  我们可以把任意一个数x表示成若干不相同的Fibonacci数的和, 比如说1 ...

  9. 2018年湘潭大学程序设计竞赛 maze(bfs)

    链接:https://www.nowcoder.com/acm/contest/105/F来源:牛客网 有q个单向传送阵,每个传送阵各有一个入口和一个出口,入口和出口都在迷宫的格子里,当走到或被传送到 ...

随机推荐

  1. 实现PIX需要参考的标准资料

    •初步了解PIX V2和V3:"IHE_ITI_TF_Rev8-0_Vol1_FT_2011-08-19"中第5章和第23章 •了解PIX V2相关事务: "IHE_IT ...

  2. poco时间操作

    Poco::DateTime Poco::Timespan Poco::Timestamp 时间操作 Poco::DateTime dt; //c++ 20才有 Calendar dt = dt + ...

  3. python3 + selenium + eclipse 中报:Unable to find a matching set of capabilities

    在环境python3 + selenium + eclipse 运行报错::Unable to find a matching set of capabilities 解决办法:Update Fire ...

  4. mysql的SQL_CALC_FOUND_ROWS /FOUND_ROWS()

    在很多分页的程序中都这样写: SELECT COUNT(*) from `table` WHERE ......;  查出符合条件的记录总数 SELECT * FROM `table` WHERE . ...

  5. 使用API修改控制台输出的颜色(前景色和背景色)

    1.api原型 SetConsoleTextAttribute BOOL WINAPI SetConsoleTextAttribute( _In_ HANDLE hConsoleOutput, // ...

  6. phpstrom添加monokai-sublime主题

    phpstrom默认的主题看起来不是特别舒服,sublime的主题却相当养眼,搜索之后,大为惊喜. 下载地址:https://github.com/sumiaowen/jetbrains-monoka ...

  7. 教程:动手用自己电脑搭建一个网站 (nat123 花生壳 动态域名 个人电脑做服务器)

    先ps一下..今晚试了N种方法,终于找到一个靠谱 免费 好用的方法,来改装自己电脑成为服务器,在外网也能通过域名访问了!!! 需要准备的东西: Tomcat:这个是web容器,其实有了这个就已经让电脑 ...

  8. C# 移除string[] 数组中的指定元素

    本文转载自  http://www.cnblogs.com/jcdd-4041/p/3279531.html 第一步:先把string[] 转换成 ArrayList   第二步:移除指定元素 第三步 ...

  9. Scrapy:Python的爬虫框架【转摘】

    网络爬虫,是在网上进行数据抓取的程序,使用它能够抓取特定网页的HTML数据.虽然我们利用一些库开发一个爬虫程序,但是使用框架可以大大提高效率,缩短开发时间.Scrapy是一个使用Python编写的,轻 ...

  10. vue-cli 3.0安装和使用

    零. 前言 公司最近开发项目使用的是vue-cli 3.0版本开发,但是对于vue-cli 3.0版本一直没有研究过如何使用,公司使用配置:pug + ts + stylus + eslint:编辑器 ...