.

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

#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. 防火墙firewall的设置和查看

    systemctl start firewalld.service # 开启防火墙firewallsystemctl stop firewalld.service # 停止防火墙firewall sy ...

  2. Redis 的学习和使用

    安装Redis 官方网站:http://redis.io/ 官方下载:http://redis.io/download 可以根据需要下载不同版本 windows版:https://github.com ...

  3. jquery的find()

    jQuery 遍历 - find() 方法 jQuery 遍历参考手册 实例 搜索所有段落中的后代 span 元素,并将其颜色设置为红色: $("p").find("sp ...

  4. CGI是什么 搜索了这么多,大致看明白了保留下来。

    转自:http://blog.chinaunix.net/uid-13408389-id-2894933.html 分类: CGI是什么 CGI是CommonGatewayInterface 的简称. ...

  5. Winform 动态 画图 不闪

    一.问题:解决winform动态画图闪的问题,网上搜的方法,大部分都是: “this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlSty ...

  6. Linux驱动platform

    platform device<==> platform bus <==> platform driver 转自:platform设备驱动全透析 宋宝华 http://blog ...

  7. ubuntu 16.04查询文件安装目录

    dpkg -L filename dpkg -l | grep filename whereis filename find / -name filename

  8. Mysql:1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'错误解决

    select distinct b.sale_count from product_sale b where b.pro_id in (select a.pro_id from product a L ...

  9. 嵌入式开发之手机arm汇总---科普手机arm

    http://www.leiphone.com/news/201406/1102-zzl-arm.html

  10. C#:ref和out的联系及区别。

    总结以上四条得到ref和out使用时的区别是: ①:ref指定的参数在函数调用时候必须初始化,不能为空的引用.而out指定的参数在函数调用时候可以不初始化: ②:out指定的参数在进入函数时会清空自己 ...