题意

题目链接

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. BZOJ2028:[SHOI2009]会场预约(线段树版)

    浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...

  2. PHP函数---$_Get()和$_Post()的用法

    一.$_Get()和$_Post()函数是用来传值的,即对应两种提交表单的方法,get和post. 二.$_Get方法 (1)获取通过URL的传值 Example 1 新建两个PHP文件,1.php, ...

  3. POCO库中文编程参考指南(8)丰富的Socket编程

    POCO库中文编程参考指南(8)丰富的Socket编程 作者:柳大·Poechant 博客:Blog.CSDN.net/Poechant 邮箱:zhongchao.ustc#gmail.com (# ...

  4. printf函数指向串口的方法

    简单地说:想在mdk 中用printf,需要同时重定义fputc函数和避免使用semihosting(半主机模式),标准库函数的默认输出设备是显示器,要实现在串口或LCD输出,必须重定义标准库函数里调 ...

  5. day1 java基础回顾-IO流

    IO流的分类 注:这几个类都是抽象类. IO解决问题: 解决设备与设备之间 的数据传输问题. 比如: 硬盘--->内存 内存----->硬盘 字节流: 输入字节流:---------| I ...

  6. Redis使用的相关问题

    Redis用那些数据结构? 字符串类型String 字典Hash 列表List 集合Set 有序集合SortedSet HyperLogLog.Geo.Pub/Sub Redis Module.Blo ...

  7. CodeForces - 1017D Round #502 D. The Wu(状压预处理)

    D. The Wu time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  8. Linear Algebra - Matrix

    1. 矩阵 定义:有 \(m*n\) 个数 \(a_{ij}(i=1,2,\cdots,m; j=1,2,\cdots,n)\) 排成的 \(m\) 行 \(n\) 列的数表 \[ \begin{Bm ...

  9. npm ERR! Cannot read property 'match' of undefined 错误处理

    跟往常一样运行npm install 的时候,突然报错.错误情况如下: npm ERR! Cannot read property 'match' of undefined npm ERR! A co ...

  10. uoj#388. 【UNR #3】配对树(线段树合并)

    传送门 先考虑一个贪心,对于一条边来说,如果当前这个序列中在它的子树中的元素个数为奇数个,那么这条边就会被一组匹配经过,否则就不会 考虑反证法,如果在这条边两边的元素个数都是偶数,那么至少有两组匹配经 ...