51nod 1358 浮点型矩阵快速幂(板子
来源:互联网 发布:杜兰特对位科比数据 编辑:程序博客网 时间:2024/06/08 04:15
1358 浮波那契
基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题
收藏
关注
TengBieBie已经学习了很多关于斐波那切数列的性质,所以他感到一些些厌烦。现在他遇到了一个新的数列,这个数列叫做Float-Bonacci。这里有一个关于Float-Bonacci的定义。
对于一个具体的n,TengBieBie想要快速计算FB(n).
但是TengBieBie对FB的了解非常少,所以他向你求助。
你的任务是计算FB(n).FB(n)可能非常大,请输出FB(n)%1,000,000,007 (1e9+7)即可。
Input
输入共一行,在一行中给出一个整数n (1<=n<=1,000,000,000)。
Output
对于每一个n,在一行中输出FB(n)%1,000,000,007 (1e9+7)。
Input示例
5
Output示例
2
G(n)=G(n-10)+G(n-34)
//china no.1#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>using namespace std;#define pi acos(-1)#define endl '\n'#define rand() srand(time(0));#define me(x) memset(x,0,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);typedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,-1,-1,1,1};const int dy[]={0,1,0,-1,1,-1,1,-1};const int maxn=1e3+5;const int maxx=1e5+100;const double EPS=1e-7;const int MOD=10000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W whileinline int Scan(){ int res=0,ch,flag=0; if((ch=getchar())=='-')flag=1; else if(ch>='0' && ch<='9')res=ch-'0'; while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0'; return flag ? -res : res;}LL a[maxx],bb[maxx],c[maxx],n,k,mod=1e9+7,t;int ssize = 34;struct Matrix{ LL m[35][35]; void init(){ memset(m, 0, sizeof m); } void setOne() { init(); for(int i=1;i<=ssize;i++) m[i][i]=1; } void unit() { m[1][10]=m[1][34] = 1; for(int i=1;i<=33;i++)m[i+1][i] = 1; } void print() { for(int i=1;i<=ssize;i++) { for(int j=1;j<=ssize;j++) cout << m[i][j] << " "; cout << endl; } cout << endl; }} I,A,B,T,b,res;Matrix Mul(Matrix a,Matrix b) //{ int i,j,k; Matrix c; for(int i=1;i<=ssize;i++) { for(int j=1;j<=ssize;j++) { c.m[i][j]=0; for(int k=1;k<=ssize;k++) { c.m[i][j]+=(a.m[i][k]*b.m[k][j]); c.m[i][j]%=mod; } } } return c;}void quickPow(LL n){ while(n) { if(n&1) res=Mul(res,b); n>>=1; b=Mul(b,b); }}int main(){ res.init(); res.setOne(); //res.print(); cin>>n; if(n<=4) { puts("1"); return 0; } n-=4; n*=10; b.unit(); quickPow(n); LL ans=0; //res.print(); FOR(1,34,i) ans+=res.m[1][i]; cout<<ans%mod<<endl;}
阅读全文
0 0
- 51nod 1358 浮点型矩阵快速幂(板子
- 矩阵快速幂(板子)
- 矩阵快速幂板子
- 矩阵快速幂 51nod
- 51Nod 1358 浮波那契 (矩阵快速幂)
- 51nod 1126(矩阵快速幂)
- 51nod 1113矩阵快速幂
- 51nod - 1573 分解 - 矩阵快速幂
- 51nod 1537 分解 (矩阵快速幂)
- 51nod-1113 矩阵快速幂
- 51nod 1113 矩阵快速幂
- 51Nod 1113 矩阵快速幂
- 51nod 矩阵快速幂模版题
- 51nod 1113 矩阵快速幂
- 51nod--1113 矩阵快速幂
- 51nod 1537 分解(矩阵快速幂)
- 51nod 1113 矩阵快速幂
- 51nod 1113 矩阵快速幂
- 优雅的代码:将处理用户界面和处理业务逻辑的代码分开
- Android——AIDL基础实现demo以及原理探究
- Thrift安装教程
- java中static的解析
- 响应式布局那些事儿
- 51nod 1358 浮点型矩阵快速幂(板子
- 第四章 编写正确的程序
- dos下常用的命令
- 大数据概述
- 数据绑定库|Android开发者 (一) [U01]
- java运行时异常与一般异常有何异同?
- c++构造函数分类说明
- Android开发:Activity的生命周期
- PCA-MATLAB 实现