hdu 2256 Problem of Precision(矩阵快速幂,得出递推式有难度)
来源:互联网 发布:多玩永恒之塔数据库 编辑:程序博客网 时间:2024/06/06 03:01
hdu 2256 Problem of Precision
这个问题的难度其实不在于矩阵的操作,而在于如何推出这个递推式,学渣给跪、、、借张图来说明
#include<stdio.h>#include<string.h>#define MOD 1024struct matrix{ int m[3][3];};matrix multi(const matrix &a,const matrix &b){ matrix ans; memset(&ans,0,sizeof(ans)); for(int i=0;i<2;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++) { ans.m[i][j]+=a.m[i][k]*b.m[k][j]; ans.m[i][j]%=MOD; } return ans;}matrix pow(matrix a,int k){ matrix ans; memset(&ans,0,sizeof(ans)); for(int i=0;i<2;i++) ans.m[i][i]=1; while(k) { if(k&1) ans=multi(ans,a); a=multi(a,a); k>>=1; } return ans;}int main(){ matrix a; int n,cas; scanf("%d",&cas); while(cas--) { scanf("%d",&n); a.m[0][0]=5,a.m[0][1]=12,a.m[1][0]=2,a.m[1][1]=5; a=pow(a,n-1); int ans=(2*(a.m[0][0]*5+a.m[0][1]*2)%MOD+MOD-1)%MOD; printf("%d\n",ans); } return 0;}
0 0
- hdu 2256 Problem of Precision(矩阵快速幂,得出递推式有难度)
- HDU 2256 Problem of Precision (矩阵快速幂)
- Hdu 2256 Problem of Precision[矩阵快速幂 + 数学]
- HDU 2256 Problem of Precision(矩阵快速幂)
- hdu 2256 Problem of Precision(矩阵快速幂 推公式)
- HDU - 2256 Problem of Precision 矩阵快速幂
- hdu 2256 Problem of Precision 矩阵快速幂
- HDU 2256 Problem of Precision(矩阵快速幂)
- HDU 2256 Problem of Precision(矩阵快速幂 数论 )
- HDU 2256 Problem of Precision(矩阵快速幂)
- HDU.2256 Problem of Precision (矩阵快速幂)
- Problem of Precision(矩阵快速幂)
- [矩阵快速幂]hdu2256 Problem of Precision
- HDU 2256 Problem of Precision 解题报告(矩阵快速幂 + 构造)
- HDU 2256 Problem of Precision(矩阵快速幂入门题)
- 【矩阵快速幂-求平方根表达式的值】HDU Problem of Precision 2256
- HDU 2256 Problem of Precision (矩阵快速幂+ 化简 +向下取整)
- hdu 2256 Problem of Precision 矩阵
- Windows下pthread多线程使用(2):CreateThread
- Hadoop RPC通信协议
- MySQL 服务器调优
- java中的io系统详解
- git 图
- hdu 2256 Problem of Precision(矩阵快速幂,得出递推式有难度)
- 常见主板故障之详解
- JSTL标签 参考手册
- 8583报文分析
- Qt中图像的显示与基本操作
- 游戏Algorithm----数组重排:将数组中的元素,根据值放到与坐标相等的位置
- 实时开发框架Meteor API解读系列<八> Timers
- 用lua实现ByteArray和ByteArrayVarint
- Deep learning these days