题目传送门

 /*
矩阵快速幂:求第n项的Fibonacci数,转置矩阵都给出,套个模板就可以了。效率很高啊
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
const int MOD = ;
struct Mat {
int m[][];
}; Mat multi_mod(Mat a, Mat b) {
Mat ret; memset (ret.m, , sizeof (ret.m));
for (int i=; i<; ++i) {
for (int j=; j<; ++j) {
for (int k=; k<; ++k) {
ret.m[i][j] = (ret.m[i][j] + a.m[i][k] * b.m[k][j]) % MOD;
}
}
}
return ret;
} int matrix_pow_mod(Mat x, int n) {
Mat ret; ret.m[][] = ret.m[][] = ; ret.m[][] = ret.m[][] = ;
while (n) {
if (n & ) ret = multi_mod (ret, x);
x = multi_mod (x, x);
n >>= ;
}
return ret.m[][];
} int main(void) { //POJ 3070 Fibonacci
int n;
while (scanf ("%d", &n) == ) {
if (n == -) break;
Mat x;
x.m[][] = x.m[][] = x.m[][] = ; x.m[][] = ;
printf ("%d\n", matrix_pow_mod (x, n));
} return ;
}

矩阵快速幂 POJ 3070 Fibonacci的更多相关文章

  1. 矩阵快速幂 POJ 3735 Training little cats

    题目传送门 /* 题意:k次操作,g:i猫+1, e:i猫eat,s:swap 矩阵快速幂:写个转置矩阵,将k次操作写在第0行,定义A = {1,0, 0, 0...}除了第一个外其他是猫的初始值 自 ...

  2. poj 3070 Fibonacci (矩阵快速幂乘/模板)

    题意:给你一个n,输出Fibonacci (n)%10000的结果 思路:裸矩阵快速幂乘,直接套模板 代码: #include <cstdio> #include <cstring& ...

  3. poj 3070 Fibonacci 矩阵快速幂

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

  4. POJ 3070 Fibonacci 【矩阵快速幂】

    <题目链接> Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 ...

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

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

  6. poj 3070 Fibonacci(矩阵快速幂,简单)

    题目 还是一道基础的矩阵快速幂. 具体的居者的幂公式我就不明示了. #include<stdio.h> #include<string.h> #include<algor ...

  7. POJ 3070 Fibonacci(矩阵快速幂)

    题目链接 题意 : 用矩阵相乘求斐波那契数的后四位. 思路 :基本上纯矩阵快速幂. #include <iostream> #include <cstring> #includ ...

  8. POJ 3070 Fibonacci矩阵快速幂 --斐波那契

    题意: 求出斐波那契数列的第n项的后四位数字 思路:f[n]=f[n-1]+f[n-2]递推可得二阶行列式,求第n项则是这个矩阵的n次幂,所以有矩阵快速幂模板,二阶行列式相乘, sum[ i ] [ ...

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

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

随机推荐

  1. 关于TableVIew的上下滚动如何探测其边界

    UITableView is a subclass of UIScrollView, and UITableViewDelegate conforms to UIScrollViewDelegate. ...

  2. The underlying JVM is how to realize the synchronized

    http://www.programering.com/a/MjN0IjMwATg.html

  3. java版大数相乘

    在搞ACM的时候遇到大数相乘的问题,在网上找了一下,看到了一个c++版本的 http://blog.csdn.net/jianzhibeihang/article/details/4948267 用j ...

  4. Android -- 系统信息(内存、cpu、sd卡、电量、版本)获取

    内存(ram)                                                                              android的总内存大小信息 ...

  5. 【每日scrum】5.3

    团队的Backlog 初期总目标:完成需求分析,做好软件前期的一切准备. 任务 认领人 估算完成时间 查找铁大离线电子地图 验证地图的准确性 万彤 司新红 3天 接口需求 (用户界面和软件接口等) 曹 ...

  6. zoj 2760 How Many Shortest Path 最大流

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 Given a weighted directed graph ...

  7. HDU 2196 求树上所有点能到达的最远距离

    其实我不是想做这道题的...只是今天考试考了一道类似的题...然后我挂了... 但是乱搞一下还是有80分....可惜没想到正解啊! 所以今天的考试题是: 巡访 (path.pas/c/cpp) Cha ...

  8. Dynamic Programming - Part2

    实现如下: public static void main(String[] args) { String squence1 = "ABCBDAB"; String squence ...

  9. phonegap/cordova常用命令

    创建项目 cordova create foldername com.wps.test projectName cd foldername 基本设备信息 设备 API: cordova plugin ...

  10. StoreKit framework

    关于In-APP Purchase 1. 中文文档 基本流程: http://www.cnblogs.com/wudan7/p/3621763.html 三种购买形式及StoreKit code介绍: ...