.

矩阵高速幂想法与快速幂相同

#include<iostream>
#include<cstdio>
#include<cstring>
#define MOD 10000
using namespace std;
struct matrix {
int mat[][];
matrix() { //构造函数与结构体同名 若写作init()函数 需调用
memset(mat,,sizeof(mat));
}
}; matrix mul(matrix A , matrix B) {
matrix C;
for(int i=;i<=;i++) {
for(int j=;j<=;j++) {
for(int k=;k<=;k++) {
C.mat[i][j]=(C.mat[i][j]+A.mat[i][k]*B.mat[k][j])%MOD;
}
}
}
return C;
} matrix powmul(matrix A ,int n) {
matrix B; //初始化为单位阵
B.mat[][]=;
B.mat[][]=;
while(n>=) {
if(n&) {
B=mul(B,A);
}
A=mul(A,A); //自身幂次
n/=;
}
return B;
} int main()
{ int n;
while(~scanf("%d",&n))
{
if(n==-) break;
matrix A;
A.mat[][]=A.mat[][]=A.mat[][]=;
A.mat[][]=;
A=powmul(A,n);
cout<<A.mat[][]<<endl;
} return ;
}

POJ 3070 矩阵mob的更多相关文章

  1. POJ ---3070 (矩阵乘法求Fibonacci 数列)

    Fibonacci   Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2  ...

  2. POJ 3070 矩阵快速幂解决fib问题

    矩阵快速幂:http://www.cnblogs.com/atmacmer/p/5184736.html 题目链接 #include<iostream> #include<cstdi ...

  3. 解题报告:poj 3070 - 矩阵快速幂简单应用

    2017-09-13 19:22:01 writer:pprp 题意很简单,就是通过矩阵快速幂进行运算,得到斐波那契数列靠后的位数 . 这是原理,实现部分就是矩阵的快速幂,也就是二分来做 矩阵快速幂可 ...

  4. POJ 3070 矩阵快速幂

    题意:求菲波那切数列的第n项. 分析:矩阵快速幂. 右边的矩阵为a0 ,a1,,, 然后求乘一次,就进一位,求第n项,就是矩阵的n次方后,再乘以b矩阵后的第一行的第一列. #include <c ...

  5. poj 3070 矩阵快速幂模板

    题意:求fibonacci数列第n项 #include "iostream" #include "vector" #include "cstring& ...

  6. 矩阵快速幂 POJ 3070 Fibonacci

    题目传送门 /* 矩阵快速幂:求第n项的Fibonacci数,转置矩阵都给出,套个模板就可以了.效率很高啊 */ #include <cstdio> #include <algori ...

  7. POJ 3070 Fibonacci(矩阵高速功率)

    职务地址:POJ 3070 用这个题学会了用矩阵高速幂来高速求斐波那契数. 依据上个公式可知,第1行第2列和第2行第1列的数都是第n个斐波那契数.所以构造矩阵.求高速幂就可以. 代码例如以下: #in ...

  8. poj 3070 && nyoj 148 矩阵快速幂

    poj 3070 && nyoj 148 矩阵快速幂 题目链接 poj: http://poj.org/problem?id=3070 nyoj: http://acm.nyist.n ...

  9. POJ 3070 + 51Nod 1242 大斐波那契数取余

    POJ 3070 #include "iostream" #include "cstdio" using namespace std; class matrix ...

随机推荐

  1. cdn日志统一下载程序

    最近实现了网宿cdn,阿里云cdn,腾讯cdn的日志统一格式下载程序,使用简单方便,有需要详见代码: https://github.com/mikeluwen/CdnLogDownload

  2. javascript 温故而知新 getBoundingClientRect

    getBoundingClientRect获取元素位置  getBoundingClientRect用于获得页面中某个元素的左,上,右和下分别相对浏览器视窗的位置. getBoundingClient ...

  3. Cygwin 版本的 Curl 安装,提取,使用笔记

    Cygwin 版本的 Curl 安装,提取,使用笔记 Cygwin 版本的 Curl 使其恢复 HTTPS 请求功能Cygwin 版本的 Curl 依赖的 DLL 清单提取 Cygwin 版本的 Cu ...

  4. gitlab配置smtp时,总是提示需要鉴权,记录一下爬坑过程。

    配置好smtp,然后发送邮件时总是提示 Net::SMTPFatalError: 550 5.7.1 authentication is required 最后发现是因为在gitlab web界面上配 ...

  5. PHP 依据IP地址获取所在城市

    有这种需求,须要依据用户的IP地址,定位用户所在的城市. 本文记录性文章,无逻辑性.有这样需求的朋友.能够直接拷贝使用.直接上代码,不需赘述. <? php header('Content-Ty ...

  6. OpenGL/GLSL数据传递小记(3.x)(转)

    OpenGL/GLSL规范在不断演进着,我们渐渐走进可编程管道的时代的同时,崭新的功能接口也让我们有点缭乱的感觉.本文再次从OpenGL和GLSL之间数据的传递这一点,记录和介绍基于OpenGL3.x ...

  7. cordova ios升级插件

    org.ssgroup.sope.cordova.upgrade 支持强制升级与选择升级 插件已经开源在https://github.com/shenshouer/org.ssgroup.sope.c ...

  8. Unable to VNC onto Centos server remotely

    用的好好的vncserver 突然遇到这个错误: [vnc@localhost ~]$ sudo systemctl status vncserver@:1.service -l● vncserver ...

  9. ios开发:如何加载大量图片 相册示例

    本文转载至 http://www.cnblogs.com/xiongqiangcs/archive/2013/06/13/3134486.html   1. Create a NSOperationQ ...

  10. [JavaScript]WebBrowser控件下IE版本的检测

    转载请注明原文地址:https://www.cnblogs.com/litou/p/10772272.htm 在客户端检查用户使用的浏览器类型和版本,都是根据navigator.userAgent属性 ...