如果有相应的OJ题目,欢迎同学们提供相应的链接

相关链接

简单的测试

None

代码模板

/*
* TIME COMPLEXITY:O(n^3log(t))
* PARAMS:
* a The constant array.
* b The initial array.
* n The length of array.
* t The iterator's value.
*
* MATRIX M:
* 0 1 0 ... 0
* 0 0 1 ... 0
* ... ... ...
* 0 0 0 ... 1
* a[n-1] a[n-2] a[n-3] ... a[0] But,here we use M.a[last row][i]=a[i],so inverse a before you call this function.
*
* MATRIX F
* b[0]
* b[1]
* .
* .
* .
* b[n] As we call M*F,the first row will gone and insert a new b[n+1]=M.a[last_row]*F.a[first_column] at the last row position.Until t is reached.
*/
int solve(int a[],int b[],int n,int t){
Matrix M,F,E;
M.clear(),F.clear(),E.clear();
M.n=M.m=n;
E.n=E.m=n;
F.n=n,F.m=1;
for(int i=0;i<n-1;i++)
M.a[i][i+1]=1;
for(int i=0;i<n;i++){
//notice:Maybe,first you should inverse a array before you call this function.
M.a[n-1][i]=a[i];
F.a[i][0]=b[i];
E.a[i][i]=1;
}
if(t<n)
return F.a[t][0];
//Here is fast Exponentiation.
for(t-=n-1;t;t/=2){
if(t&1)
E=M*E;
M=M*M;
}
F=E*F;
return F.a[n-1][0];
}

模板-->常系数线性齐次递推(矩阵快速幂)的更多相关文章

  1. 2019牛客暑期多校训练营(第五场)- B generator 1 (齐次线性递推+矩阵快速幂)

    题目链接:https://ac.nowcoder.com/acm/contest/885/B 题意:已知齐次线性式xn=a*xn-1+b*xn-2,已知a,b,x0,x1,求xn,n很大,n<= ...

  2. HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  3. hdu 2604 递推 矩阵快速幂

    HDU 2604 Queuing (递推+矩阵快速幂) 这位作者讲的不错,可以看看他的 #include <cstdio> #include <iostream> #inclu ...

  4. POJ3070 斐波那契数列递推 矩阵快速幂模板题

    题目分析: 对于给出的n,求出斐波那契数列第n项的最后4为数,当n很大的时候,普通的递推会超时,这里介绍用矩阵快速幂解决当递推次数很大时的结果,这里矩阵已经给出,直接计算即可 #include< ...

  5. 2017中国大学生程序设计竞赛 - 女生专场 Happy Necklace(递推+矩阵快速幂)

    Happy Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  6. HDU 2842 (递推+矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...

  7. Recursive sequence HDU - 5950 (递推 矩阵快速幂优化)

    题目链接 F[1] = a, F[2] = b, F[i] = 2 * F[i-2] + F[i-1] + i ^ 4, (i >= 3) 现在要求F[N] 类似于斐波那契数列的递推式子吧, 但 ...

  8. HDU6030 Happy Necklace(递推+矩阵快速幂)

    传送门:点我 Little Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of ...

  9. 五校联考R1 Day1T3 平面图planar(递推 矩阵快速幂)

    题目链接 我们可以把棱柱拆成有\(n\)条高的矩形,尝试递推. 在计算的过程中,第\(i\)列(\(i\neq n\))只与\(i-1\)列有关,称\(i-1\)列的上面/下面为左上/左下,第\(i\ ...

随机推荐

  1. Nginx fastcgi_param解释

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#脚本文件请求的路径 fastcgi_param QUERY_STRI ...

  2. E题 - A+B for Input-Output Practice (IV)

      Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description You ...

  3. uboot使用tftp下载时出现“checksum bad”问题原因分析

    一.问题 二.原因分析 你的虚拟机是不是这样设置的呢? 如果是的话,请看下边的解释: 使用NAT模式,就是让虚拟系统借助NAT(网络地址转换)功能,通过宿主机器所在的网络来访问公网.也就是说,使用NA ...

  4. PHP框架、库和软件资源大全(整理篇)

    php的资料 https://github.com/ziadoz/awesome-php Awesome PHP A curated list of amazingly awesome PHP lib ...

  5. Inna and Binary Logic

    Codeforces Round #234 (Div. 2) E:http://codeforces.com/problemset/problem/400/E 题意:给你n个数,然后每相邻的两个数可以 ...

  6. H3C S5500上层接路由,VLAN IP作网站配置实例

    # version 5.20, Release 2208 # sysname S5500-1 # clock timezone #Web#8#01 add 08:00:00 # super passw ...

  7. h.264语法结构分析

    NAL Unit Stream Network Abstraction Layer,简称NAL. h.264把原始的yuv文件编码成码流文件,生成的码流文件就是NAL单元流(NAL unit Stre ...

  8. 怎样在delphi中实现控件和窗体的拖拽

    下面这2种方法都能实现对控件和窗体的拖拽 方法1 procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift ...

  9. scheme和common lisp 区别

    Scheme and Common Lisp use different names for some of the basic system functions. Many Lisp program ...

  10. Linux Shell编程(6)——变量替换

    变量的名字是它的值保存的地方.引用它的值称为变量替换.$让我们仔细地区别变量和变量的值.如果variable1是一个变量的名字,那么$variable1就是引用这个变量的值――即这个变量它包含的数据. ...