题目大意:

f[1]=1 f[2]=2

f[n]=f[n-1]+2*f[n-2]+n^3

在某博客截的图 现在忘记原博位置了 抱歉

根据递推式1和递推式3构造出两个矩阵

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define inc(i,j,k) for(int i=j;i<=k;i++)
#define dec(i,j,k) for(int i=j;i>=k;i--)
#define gcd(i,j) __gcd(i,j)
#define mem(i,j) memset(i,j,sizeof(i))
const int N=1e5+;
const int M=;
const int mod=; LL n,m;
struct MAT {
LL a[M][M];
MAT(){ mem(a,); }
MAT operator*(MAT p) {
MAT res;
for(int i=;i<M;i++)
for(int j=;j<M;j++)
for(int k=;k<M;k++)
res.a[i][j]=(res.a[i][j]+a[i][k]*p.a[k][j])%mod;
return res;
}
};
MAT mod_pow(MAT A,LL x) {
MAT res;
res.a[][]=;
while(x) {
if(x&) res=res*A;
A=A*A; x>>=;
}
return res;
}
void init(MAT& A,MAT& B) {
A.a[][]=,A.a[][]=,A.a[][]=,
A.a[][]=,
A.a[][]=,A.a[][]=,A.a[][]=,A.a[][]=,
A.a[][]=,A.a[][]=,A.a[][]=,
A.a[][]=,A.a[][]=,
A.a[][]=;
B.a[][]=,B.a[][]=,B.a[][]=,B.a[][]=,B.a[][]=,B.a[][]=;
} int main()
{
int _; scanf("%d",&_);
while(_--) {
LL n; scanf("%lld",&n);
MAT A; MAT ans;
init(A,ans);
ans=mod_pow(A,n-2LL)*ans;
printf("%lld\n",ans.a[][]);
} return ;
}

HDU 6470 /// 矩阵快速幂的更多相关文章

  1. HDU 2855 (矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2855 题目大意:求$S(n)=\sum_{k=0}^{n}C_{n}^{k}Fibonacci(k)$ ...

  2. HDU 4471 矩阵快速幂 Homework

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4471 解题思路,矩阵快速幂····特殊点特殊处理····· 令h为计算某个数最多须知前h个数,于是写 ...

  3. HDU - 1575——矩阵快速幂问题

    HDU - 1575 题目: A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973.  Input数据的第一行是一个T,表示有T组数据. 每组数据的第一行有n( ...

  4. hdu 1757 (矩阵快速幂) 一个简单的问题 一个简单的开始

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 题意不难理解,当x小于10的时候,数列f(x)=x,当x大于等于10的时候f(x) = a0 * ...

  5. 随手练——HDU 5015 矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5015 看到这个限时,我就知道这题不简单~~矩阵快速幂,找递推关系 我们假设第一列为: 23 a1 a2 ...

  6. HDU 3802 矩阵快速幂 化简递推式子 加一点点二次剩余知识

    求$G(a,b,n,p) = (a^{\frac {p-1}{2}}+1)(b^{\frac{p-1}{2}}+1)[(\sqrt{a} + \sqrt{b})^{2F_n} + (\sqrt{a} ...

  7. How many ways?? HDU - 2157 矩阵快速幂

    题目描述 春天到了, HDU校园里开满了花, 姹紫嫣红, 非常美丽. 葱头是个爱花的人, 看着校花校草竞相开放, 漫步校园, 心情也变得舒畅. 为了多看看这迷人的校园, 葱头决定, 每次上课都走不同的 ...

  8. HDU 5950 矩阵快速幂

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. hdu 1757 矩阵快速幂 **

    一看正确率这么高,以为是水题可以爽一发,结果是没怎么用过的矩阵快速幂,233 题解链接:点我 #include<iostream> #include<cstring> ; us ...

随机推荐

  1. rabbitmq AmqpClient 使用Direct 交换机投递与接收消息,C++代码示例

    // 以DIRECT 交换机和ROUTING_KEY的方式进行消息的发布与订阅 // send // strUri = "amqp://guest:guest@192.168.30.11:8 ...

  2. Vue:子组件如何跟父组件通信

    我们知道,父组件使用 prop 传递数据给子组件.但子组件怎么跟父组件通信呢?这个时候 Vue 的自定义事件系统就派得上用场了. 使用 v-on 绑定自定义事件 每个 Vue 实例都实现了事件接口,即 ...

  3. VMware Tool的新手简单安装

    1.打开工具栏的虚拟机,点击安装VMware tool2.打开根目录的media文件夹,打开用户名命名的文件夹,复制VMxxx.tar.gz的压缩包3.粘贴到Home,4.在终端输入tar -zxvf ...

  4. C# RSA加密

    /// <summary> /// 类名:RSACrypt /// 功能:RSA加密.解密.签名.验签 /// </summary> public sealed class R ...

  5. bzoj4489 [Jsoi2015]地铁线路 最短路

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4489 题解 感觉又被骗了.看这道题的 AC 人数不多,以为是一道很好的题目.结果发现是一个非常 ...

  6. vue自定义抽屉组件

    <template> <div class="drawer"> <div :class="maskClass" @click=&q ...

  7. 单词计数-MapReduceJob

    pom文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3. ...

  8. linux内核源码——内存管理:段页式内存及swap

    os的内存管理大概可以分成两块:1.段页式管理(虚存)2.swap in 和 swap out 段页式管理 段式管理的图像:运行时重定位 多级页表的管理图像  块表加速 用户(程序员)希望用段,物理内 ...

  9. 获取数组NSArray元素的className

    正确读取NSArray里面元素的Class类型的方法 object_getClass(columnsArray.firstObject) 错误的方法是 [columnsArray.firstObjec ...

  10. mysql创建,添加主键

    primary key 1.最简单的: CREATE TABLE t1( id int not null, name char(20)); 2.带主键的: a:CREATE TABLE t1( id ...