POJ3070:Fibonacci——题解】的更多相关文章

http://poj.org/problem?id=3070 题目大意:求Fibonacci数列第n项,对10000取模. 矩阵乘法板子题……实在不知道写什么了. #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<queue> using namespace std; typedef lo…
Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13677   Accepted: 9697 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequenc…
Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, - An alternative formula for the Fibonacci sequence is…
Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13677   Accepted: 9697 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequenc…
题目链接:http://poj.org/problem? id=3070 题目大意:给定n和10000,求第n个Fibonacci数mod 10000 的值,n不超过2^31. 结果保留四位数字. 非常easy的题,和之前做过的相比简单非常多了. 构造最简单的斐波那契数列矩阵. #include<iostream> #include<cstring> #include<stdio.h> using namespace std; const int MAX = 2; st…
题目传送门 如果之前推过斐波那契数列前缀和就更好做(所以题目中给出了). 斐波那契数列前缀和题目链接 先来推一下斐波那契数列前缀和: \[\sum\limits_{i=1}^nf(i) \] 其中 \(f(i)\) 表示Fibonacci数列第 \(i\) 项. 直接推式子: 记 \(s(x)=\sum\limits_{i=1}^xf(i)\) 将右边一项项展开得出 \[f(1)=1 \] \[f(2)=1 \] \[f(3)=f(1)+f(2) \] \[f(4)=f(2)+f(3) \] \…
学了线代之后 终于明白了矩阵的乘法.. 于是 第一道矩阵快速幂.. 实在是太水了... 这差不多是个模板了 #include <cstdlib> #include <cstring> #include <cstdio> #include <iostream> using namespace std; int N; struct matrix { int a[3][3]; }origin,res; matrix multiply(matrix x,matrix…
题目链接:传送门 题目大意: 求斐波那契数列第n项F(n). (F(0) = 0, F(1) = 1, 0 ≤ n ≤ 109) 思路: 用矩阵乘法加速递推. 算法竞赛进阶指南的模板: #include <iostream> #include <cstring> using namespace std; ; ], ][]) { ]; memset(c, , sizeof c); ; j < ; j++) { ; k < ; k++) { c[j] = (c[j] + 1…
传送门 矩阵快速幂板题,写一道来练练手. 这一次在poj做题总算没忘了改万能库. 代码: #include<iostream> #include<cstdio> #define mod 10000 #define A a[0][0] #define B a[0][1] #define C a[1][0] #define D a[1][1] using namespace std; int n; struct Matrix{int a[2][2];Matrix(){A=0,B=C=D…
矩阵快速幂基本应用. 对于矩阵乘法与递推式之间的关系: 如:在斐波那契数列之中 f[i] = 1*f[i-1]+1*f[i-2]  f[i-1] = 1*f[i-1] + 0*f[i-2].即 所以, 就这两幅图完美诠释了斐波那契数列如何用矩阵来实现. #include<iostream> #include<cstring> using namespace std; typedef long long ll; ; struct mat{ ll a[][]; }; mat mat_m…