找出递推关系式就好了

(fi+1)=(1  -1)(fi  )

(    fi)=(1   0)(fi-1)

不会打矩阵将就着看吧。。。

这是第一道矩阵快速幂。细节还是有很多没注意到的

本来想看挑战写的,结果上面的vector套vector看的我头都晕了。。

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=<<+,inf=0x3f3f3f3f; struct Node{
ll row,col;
ll a[N][N];
};
Node mul(Node x,Node y)
{
Node ans;
memset(ans.a,,sizeof ans.a);
ans.row=x.row,ans.col=y.col;
for(ll i=;i<x.row;i++)
for(ll j=;j<y.row;j++)
for(ll k=;k<y.col;k++)
ans.a[i][k]=(ans.a[i][k]+x.a[i][j]*y.a[j][k]+mod)%mod;
return ans;
}
Node quick_mul(Node x,ll n)
{
Node ans;
ans.row=x.row;
ans.col=x.col;
memset(ans.a,,sizeof ans.a);
for(int i=;i<ans.row;i++)ans.a[i][i]=;
while(n){
if(n&)ans=mul(ans,x);
x=mul(x,x);
n/=;
}
return ans;
}
int main()
{ ios::sync_with_stdio(false);
cin.tie();
// cout<<setiosflags(ios::fixed)<<setprecision(2);
int x,y,n;
cin>>x>>y>>n;
if(n==)
{
cout<<(x+mod)%mod<<endl;
return ;
}
Node A,B;
A.row=,A.col=;
A.a[][]=,A.a[][]=-;
A.a[][]=,A.a[][]=;
/* for(int i=0;i<A.row;i++)
{
for(int j=0;j<A.col;j++)
cout<<A.a[i][j]<<" ";
cout<<endl;
}*/
B.row=,B.col=;
B.a[][]=y,B.a[][]=x;
cout<<(mul(quick_mul(A,n-),B).a[][]+mod)%mod<<endl;
return ;
}

codefroces 450B矩阵快速幂的更多相关文章

  1. cf 450b 矩阵快速幂(数论取模 一大坑点啊)

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  2. CodeForces 450B Jzzhu and Sequences(矩阵快速幂)题解

    思路: 之前那篇完全没想清楚,给删了,下午一上班突然想明白了. 讲一下这道题的大概思路,应该就明白矩阵快速幂是怎么回事了. 我们首先可以推导出 学过矩阵的都应该看得懂,我们把它简写成T*A(n-1)= ...

  3. Codeforces 450B div.2 Jzzhu and Sequences 矩阵快速幂or规律

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  4. codeforces 450B B. Jzzhu and Sequences(矩阵快速幂)

    题目链接: B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input ...

  5. 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)

    题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...

  6. 51nod 算法马拉松18 B 非010串 矩阵快速幂

    非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...

  7. 51nod 1113 矩阵快速幂

    题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...

  8. 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】

    还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...

  9. HDU5950(矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:f(n) = f(n-1) + 2*f(n-2) + n^4,f(1) = a , f(2 ...

随机推荐

  1. ELK+Kafka学习笔记之搭建ELK+Kafka日志收集系统集群

    0x00 概述 关于如何搭建ELK部分,请参考这篇文章,https://www.cnblogs.com/JetpropelledSnake/p/9893566.html. 该篇用户为非root,使用用 ...

  2. Python3.x:关于urllib中urlopen报错问题的解决方案

    Python3.x:关于urllib中urlopen报错问题的解决方案 调用:urllib.urlopen(url) 报错:AttributeError: 'module' object has no ...

  3. 安装使用composer基本流程

    composer工作原理: 这里经过几个步骤:1.composer读取composer.json(这个文件手动建立,官网有格式),这个json是在当前执行composer目录的,如果目录下没有这个js ...

  4. 20145318《网络对抗》Web应用

    20145318<网络对抗>Web应用 基础问题回答 (1)什么是表单 在网页中负责信息采集,在网页中用户输入信息,通过表单能够提交到后台进行相应的处理 (2)浏览器可以解析运行什么语言 ...

  5. 20144303石宇森《网络对抗》注入shellcode和Return-to-libc攻击

    20144303石宇森<网络对抗>PC平台逆向破解 实验1:shellcode注入 实验基础 1.Linux下有两种基本构造攻击buf的方法:retaddr+nop+shellcode,n ...

  6. VS编译器之间相互打开的技巧

    例如:VS2010的工程在VS2012上打开,在工程属性里面 选择“常规” --> "平台工具集中"   选择 正在打开版本的型号.

  7. 从bios启动说起

    如果从bios启动说起的话,BIOS去加载bootloader,bootloader去加载操作系统,那么bootloader是怎么找到操作系统的呢?经过一些流程后,它会去找grub:然后通过grub提 ...

  8. 【第十四章】 springboot + profile(不同环境读取不同配置)

    具体做法: 不同环境的配置设置一个配置文件,例如:dev环境下的配置配置在application-dev.properties中:prod环境下的配置配置在application-prod.prope ...

  9. [Shiro] - Shiro之SpringBoot中的使用

    下载了运行项目后,访问路径:http://localhost/shiro/login 这篇应该在进阶后面的. shiro中的重中之重,一定要看. 基于springboot+thymeleaf+shir ...

  10. Unity3D学习笔记(十):Physics类和射线

    物理系统:碰撞器.触发器等 力:有大小有方向的矢量,有受力点位置(和向量的区别) ----F = ma(m质量,a加速度,质量越大,加速度越小,停下来越慢) ----m1v1 = m2v2(冲量守恒定 ...