hrbust 1126 HLG 矩阵快速幂
来源:互联网 发布:dell校色软件 编辑:程序博客网 时间:2024/05/14 07:31
再来一个模板题
这题也是找递推的矩阵
111100010Final Destination IITime Limit: 1000 MSMemory Limit: 65536 KTotal Submit: 392(116 users)Total Accepted: 157(89 users)Rating: Special Judge: NoDescriptionJiaoZhu likes going on adventure! One day, he walks into a big castle, and there is an unique stairway. JiaoZhu finds a board ,it says “The one who want to go upstairs only can go three steps the most once, meaning that you can go 1 or 2 or 3 steps once!”. Now, we have a problem, can you tell me the number of ways to go to the destination? If you can’t ,death is the only choice。
In the beginning, you are in the 0th step.
InputFirst input a integer T(T<50), represent the number of case.
Each case ,the input will consist only a positive integer n (0<=n<=1000000000), represent the nth steps you want to go to..
OutputOrder the sample output format to output.
Line 1,print the Case k.
Line 2,print one integer represent the number of ways to go to nth steps.(MOD 1000000007)
Sample InputWhen n=2,you can go one step once to go to 2th ,or go 2 steps once to 2th,so the answer is 2.
Author齐达拉图#include<stdio.h>#define MOD 1000000007#define ll long longstruct nana{ ll m[3][3];}h,l;nana juzhen(nana a,nana b){ nana temp; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { temp.m[i][j]=0; for(int k=0;k<3;k++) { temp.m[i][j]=(temp.m[i][j]+a.m[i][k]*b.m[k][j])%MOD; } } } return temp;}ll zzz(ll n){ for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { if(i==j) h.m[i][j]=1; else h.m[i][j]=0; } } l.m[0][0]=l.m[0][1]=l.m[0][2]=l.m[1][0]=l.m[2][1]=1; l.m[1][1]=l.m[1][2]=l.m[2][0]=l.m[2][2]=0; while(n) { if(n%2==1) h=juzhen(h,l); l=juzhen(l,l); n=n/2; } return h.m[0][0];}int main(){ ll k=0; ll n; int t; scanf("%d",&t); while(t--){ scanf("%lld",&n); printf("Case %lld:\n",++k); printf("%lld\n",zzz(n));}}
- hrbust 1126 HLG 矩阵快速幂
- HLG-1126(矩阵乘法+快速幂)
- HLG 1126 Final Destination II(快速幂,矩阵乘法)
- HLG 1905 f(N) 矩阵快速幂
- HLG-1375(矩阵乘法+快速幂)
- hrbust 1430 矩阵快速幂
- HRBUST 1126 Final Destination II (矩阵快速幂)
- hrbust 2190 矩阵快速幂模板
- HLG-1251(快速幂)
- HRBUST 1855 幼稚园的矩阵(矩阵快速幂)
- hrbust/哈理工oj 1126 Final Destination II【矩阵快速幂+递推】
- hrbust 1430 神秘植物 [递推+矩阵快速幂]
- HRBUST 1430 神秘植物 (矩阵快速幂)
- hrbust/哈理工oj 1592 六芒星【矩阵快速幂】
- hrbust 1401 九连环(矩阵快速幂)
- Hrbust 1401 九连环【递推+矩阵快速幂】
- hrbust 又是Fibonacci (矩阵快速幂)
- HLG 1375 The Active Leyni (快速幂,动态规划,矩阵乘法)
- c++流库
- eclipse重命名项目之后
- C语言学习笔记(6)-如何从变量声明的表面上来区分指针数组和数组指针
- java的三大特性之一(封装)
- 数学理论-----向量范数和矩阵范数理解
- hrbust 1126 HLG 矩阵快速幂
- 接上一篇spring4.2+SpringDataRedis消息队列+Junit4
- 页面传入Excel表格,Aspose.cells导入功能
- 1037:找出N之内的所有完数
- 将wordpress安装到已经是lnmp环境的腾讯云服务器
- UVa272 - Tex Quotes
- CSS基础知识
- 使用信号量解决两个线程同步问题
- c++对结构体数组排序