如果有相应的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. php计算时间差/两个时间日期相隔的天数,时,分,秒.

    function timediff( $begin_time, $end_time ) { if ( $begin_time < $end_time ) { $starttime = $begi ...

  2. Windows Phone 学习笔记(一) 数据存储

    独立存储设置IsolatedStorageSetting private IsolatedStorageSettings _appSettings; public MainPage() { Initi ...

  3. 从相对路径说开来(从C++到Qt)

    从相对路径说开来(从C++到Qt) 转载自:http://blog.csdn.net/dbzhang800/article/details/6363165 在Qt论坛经常看到网友抱怨: QPixmap ...

  4. 应用程序的关闭退出(在FMX中,Activity替代了Form的概念)

    在VCL中,关闭程序的主窗体也就意味着程序的主循环结束,主程序自然而然结束.所以在主窗体中使用窗体的关闭函数(Close)即可,如下: procedure TfrmMain.btncloseClick ...

  5. Linux 配置多IP

    这里以红帽Linux为例.假定原系统已配置一个IP,地址为:192.168.20.140,配置文件路径/etc/sysconfig/network-script/ifcfg-eth0.现在需要配置一个 ...

  6. texedo 分布式事务

    1.问题现象 但是实际情况,完全出乎笔者的想法.检查一般对象数据表锁定,只需要检查v$locked_object和v$transaction视图,就可以定位到具体人.但是检查之后的结果如下: SQL& ...

  7. .net ref关键字在引用类型上的使用

    只接上干货. namespace ConsoleApplication1 { class Person { public string UserName { get; set; } } class P ...

  8. 「Poetize3」导弹防御塔

    描述 Description Freda控制着N座可以发射导弹的防御塔.每座塔都有足够数量的导弹,但是每座塔每次只能发射一枚.在发射导弹时,导弹需要T1秒才能从防御塔中射出,而在发射导弹后,发射这枚导 ...

  9. wpa_cli 连接 wifi

    转自:http://hi.baidu.com/yyangjjun/item/9dfe8e175439fc7a1009b5ba   1: run wpa_supplicant first use the ...

  10. 高效算法——E - 贪心-- 区间覆盖

    E - 贪心-- 区间覆盖 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/E 解题思路: 贪心思想, ...