题目链接:http://poj.org/problem?id=3070

.

就是斐波那契的另一种表示方法是矩阵的幂;

所以是矩阵快速幂;矩阵快速幂学习

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<math.h>
using namespace std;
#define N 10 struct node
{
int a[N][N];
}s,e; node mul(node p, node q)///求两个矩阵的积;
{
node tem;
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
tem.a[i][j] = ;
for(int k=; k<; k++)
tem.a[i][j] = (tem.a[i][j]+p.a[i][k]*q.a[k][j])%;
}
}
return tem;
}
node Pow(node p, int n)
{
node tem;
for(int i=; i<; i++)
for(int j=; j<; j++)
tem.a[i][j] = (i==j);
while(n)
{
if(n&)///n是奇数;
tem = mul(tem, p);///让矩阵e和矩阵a相乘;
n/=;
p = mul(p, p);
}
return tem;
} int main()
{
s.a[][] = ;
s.a[][] = ;
s.a[][] = ;
s.a[][] = ;
int n;
while(scanf("%d", &n),n!=-)
{
e = Pow(s, n);
printf("%d\n", e.a[][]);
}
return ;
}

对比着想想快速幂;

Fibonacci----poj3070(矩阵快速幂, 模板)的更多相关文章

  1. POJ3070 矩阵快速幂模板

    题目:http://poj.org/problem?id=3070 矩阵快速幂模板.mod写到乘法的定义部分就行了. 别忘了 I ( ) 和 i n i t ( ) 要传引用! #include< ...

  2. 矩阵快速幂模板(pascal)

    洛谷P3390 题目背景 矩阵快速幂 题目描述 给定n*n的矩阵A,求A^k 输入输出格式 输入格式: 第一行,n,k 第2至n+1行,每行n个数,第i+1行第j个数表示矩阵第i行第j列的元素 输出格 ...

  3. 51nod1113(矩阵快速幂模板)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1113 题意:中文题诶- 思路:矩阵快速幂模板 代码: #inc ...

  4. luoguP3390(矩阵快速幂模板题)

    链接:https://www.luogu.org/problemnew/show/P3390 题意:矩阵快速幂模板题,思路和快速幂一致,只需提供矩阵的乘法即可. AC代码: #include<c ...

  5. hdu 3117 Fibonacci Numbers 矩阵快速幂+公式

    斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...

  6. POJ 3070 Fibonacci 矩阵快速幂模板

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18607   Accepted: 12920 Descr ...

  7. 2018.09.25 poj3070 Fibonacci(矩阵快速幂)

    传送门 矩阵快速幂板题,写一道来练练手. 这一次在poj做题总算没忘了改万能库. 代码: #include<iostream> #include<cstdio> #define ...

  8. poj3070 Fibonacci(矩阵快速幂)

    矩阵快速幂基本应用. 对于矩阵乘法与递推式之间的关系: 如:在斐波那契数列之中 f[i] = 1*f[i-1]+1*f[i-2]  f[i-1] = 1*f[i-1] + 0*f[i-2].即 所以, ...

  9. POJ3070 斐波那契数列递推 矩阵快速幂模板题

    题目分析: 对于给出的n,求出斐波那契数列第n项的最后4为数,当n很大的时候,普通的递推会超时,这里介绍用矩阵快速幂解决当递推次数很大时的结果,这里矩阵已经给出,直接计算即可 #include< ...

  10. hdu3306 Another kind of Fibonacci【矩阵快速幂】

    转载请注明出处:http://www.cnblogs.com/KirisameMarisa/p/4187670.html 题目链接:http://acm.hdu.edu.cn/showproblem. ...

随机推荐

  1. 基于jquery的适合电子商务网站首页的图片滑块

    今天给大家分享一款基于Sequence.js 的图片滑动效果,特别适合电子商务网站或者企业产品展示功能.带有图片缩率图,能够呈现全屏图片浏览效果.结合 CSS3 Transition 实现响应式的滑块 ...

  2. am335x alsa codec调试

    root@phyCORE-AM335x:~ aplay -l**** List of PLAYBACK Hardware Devices ****card 0: audio [PCM051 audio ...

  3. 【转】H5页面的测试点总结

    在此对H5页面的测试点(以及容易出问题的点)  1.业务逻辑相关  除基本的功能测试之外,H5页面的测试,需要关注以下几点:  1.1 登陆  目前H5与native各个客户端都做了互通,所以大家在测 ...

  4. Python之并行

    http://www.open-open.com/news/view/1c0179b/

  5. Linux Shell Vim 经常使用命令、使用技巧总结

    前言 本文总结了自己实际开发中的经常使用命令,不定时更新,方便自己和其它人查阅. 如有其它提高效率的使用技巧.欢迎留言. 本文地址 http://blog.csdn.net/never_cxb/art ...

  6. JSON美化输出

    echo '{"a": 1, "b": 2}' | python -m json.tool 转自: http://blog.csdn.net/chosen0ne ...

  7. gcc参数PIE和PIC的区别和共同点

    gcc参数的PIE和PIC 区别 PIE:用在可执行文件 PIC:用在库文件 共同点 生成跟位置没有关系的symbol

  8. Socket的三个关联函数

    /*lrs_save_param将静态或接收到的缓冲区保存到参数中*/lrs_save_param (char *s_desc, char *buf_desc, char *param_name, i ...

  9. 我的Android进阶之旅------&gt;MIME类型大全

    今天在实现一个安装apk的代码中看到一段代码为:application/vnd.android.package-archive.不知其意.所以百度了一下,了解到这是一种MIME的类型,代表apk类型. ...

  10. mybatis 控制台打印出来的sql 执行结果为空 但是将sql放到mysql执行有数据

    mybatis中的sql如下 select airln_Cd airlnCd,city_coordinate_j cityCoordinateJ,city_coordinate_w cityCoord ...