题目传送门

 /*
矩阵快速幂:求第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. iOS学习之C语言函数

    一.函数的定义 返回值类型 函数名(参数类型 参数名, ...) { 功能语句; return 返回值; } 按照返回值和参数划分: 第一种: 无返回值 无参 void sayHello() { pr ...

  2. iOS学习之C语言循环结构

    一.while循环    while (循环条件) {        循环体:    }    // 1.定义循环变量    int time = 1;    // 2.循环条件    while ( ...

  3. 未能加载文件或程序集“System.Web.Razor”或它的某一个依赖项。文件或目录损坏且无法读取。

    “/”应用程序中的服务器错误. 未能加载文件或程序集“System.Web.Razor”或它的某一个依赖项.文件或目录损坏且无法读取. (异常来自 HRESULT:0x80070570) 说明: 执行 ...

  4. 微信扫码支付asp.net(C#)实现步骤

    支付提交页面: [HttpPost] public ActionResult index(decimal amount) { //生成订单10位序列号,此处用时间和随机数生成,商户根据自己调整,保证唯 ...

  5. Python MYSQL - tiny ETL tool - 文件操作和数据库操作

    import os import MySQLdb Con= MySQLdb.connect(host=',db='test') #链接数据库 cur=Con.cursor() os.chdir(&qu ...

  6. 38.基于FPGA的FIR设计二

    利用fdatool工具生成的滤波器系数与用代码生成的系数不一致,在网上查询得知,fdatool生成的滤波器系数是有符号小数,而且是浮点型,而代码生成的滤波器系数是定点型有符号数,故不一样. 浮点型数据 ...

  7. [shell基础]——awk命令

    关于awk awk是一个强大的文本分析工具,相对于grep的查找.sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大. 简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开 ...

  8. jquery ajax 传递js对象到后台

    第一种:通过struts接收 (function ($) { $("#btnsave").click(function () { var params = {}; params[& ...

  9. linux查看端口是否已开启和查看文件数

    查看端口是否开启 lsof -i:80 查看文件数 ls | wc -w

  10. iframe 传值问题

    当一个页面中插入了iframe或者由不同的框架组成(fieldset)时,这种情况下,需要处理的业务逻辑比较常见的就是数据进行交互了 1.页面中插入了iframe情况 由于页面中插入了iframe,那 ...