【矩阵计算/快速幂】
herongweiV
喜爱编程,热爱算法。
展开
-
矩阵快速幂--学习笔记
据说,矩阵快速幂在递推式优化上相当神奇,而且效率很高。。。 两矩阵相乘,朴素算法的复杂度是O(N^3)。如果求一次矩阵的M次幂,按朴素的写法就是O(N^3*M)。既然是求幂,不免想到快速幂取模的算法,这里有快速幂取模的介绍,a^b %m 的复杂度可以降到O(logb)。如果矩阵相乘是不是也可以实现O(N^3 * logM)的时间复杂度呢?答案是肯定的。 先定义矩阵数据结构:转载 2014-10-11 09:55:37 · 1063 阅读 · 0 评论 -
一类常见的矩阵快速幂题型 总结
Googlecode jam 2008 Round 1A(c.Numbers)【题意】计算的小数点前三位数,不足三位补0,正整数n的最大值为20亿。【前提】:满足的值在【0,1】范围首先将展开之后可以发现的形式,同样的,有因此,是个整数,其中这正是解题的关键!由于所以的整原创 2015-09-21 23:59:45 · 1949 阅读 · 0 评论 -
【构造共轭函数+矩阵快速幂】HDU 4565 So Easy! (2013 长沙赛区邀请赛)
链接 :click here~~题意: A sequence Sn is defined as:Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate Sn. You, a top coder, say: So eas原创 2015-04-08 10:01:52 · 1401 阅读 · 2 评论 -
HDU 1757 A Simple Math Problem (矩阵快速幂)
【题目链接】:click here~~【题目大意】:If x If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10); 问f(k)%m的值。【思路】:矩阵快速幂,具体思路看代码吧,注意一些细节。代码:#includeusing namespace std;typede原创 2015-08-29 21:36:58 · 833 阅读 · 0 评论 -
CSU - 1556 Jerry's trouble(快速幂取模)
【题目链接】:click here~~\【题目大意】:计算x1^m+x2^m+..xn^m(1 1 )【解题思路】: 快速幂取模代码:#include#define LL long longusing namespace std;const LL mod=(LL)1e9+7;LL pow_mod(LL a,LL p,LL n){ if(p==0) return原创 2015-06-28 23:16:30 · 922 阅读 · 0 评论 -
【矩阵快速幂 】Codeforces 450B - Jzzhu and Sequences (公式转化)
【题目链接】click here~~【题目大意】Jzzhu has invented a kind of sequences, they meet the following property:You are given x and y, please calculate fn modulo1000000007(109 + 7).【解题思路】原创 2015-04-11 20:59:44 · 2126 阅读 · 3 评论 -
FZU 1692 Key problem(构造矩阵+矩阵快速幂)
【题目链接】点击打开FZU 1692【题意】:1 题目的意思是有n个人构成一个圈,每个人初始的有ai个苹果,现在做m次的游戏,每一次游戏过后第i个人能够增加R*A(i+n-1)%n+L*A(i+1)%n 个苹果(题目有错),问m轮游戏过后每个人的苹果数【思路】:根据题目的意思我们能够列出一轮过后每个人的苹果数 a0 = a0+R*an-1+L*a1原创 2015-09-04 12:25:02 · 665 阅读 · 0 评论 -
HDU 2604 Queuing (递推+矩阵快速幂)
【题目链接】:click here~~【题目大意】:n个人排队,f表示女,m表示男,包含子串‘fmf’和‘fff’的序列为O队列,否则为E队列,有多少个序列为E队列。【思路】:用f(n)表示n个人满足条件的结果,那么如果最后一个人是m的话,那么前n-1个满足条件即可,就是f(n-1); 如果最后一个是f那么这个还无法推出结果,那么往前再考虑一位:那么后三位可能是:mmf,原创 2015-08-29 21:43:30 · 972 阅读 · 0 评论 -
hihoCoder #1143 : 骨牌覆盖问题·一
【题目链接】:click here~~时间限制:10000ms单点时限:1000ms内存限制:256MB描述骨牌,一种古老的玩具。今天我们要研究的是骨牌的覆盖问题:我们有一个2xN的长条形棋盘,然后用1x2的骨牌去覆盖整个棋盘。对于这个棋盘,一共有多少种不同的覆盖方法呢?举个例子,对于长度为1到3的棋盘,我们有下面几种覆盖方式:原创 2015-06-09 07:52:43 · 2511 阅读 · 0 评论 -
【矩阵快速幂】UVA 10698 G - Yet another Number Sequence
【题目链接】click here~~【题目大意】Let's define another number sequence, given by the following function:f(0) = a f(1) = b f(n) = f(n-1) + f(n-2), n > 1When a = 0 and b = 1, this sequence gives the原创 2015-04-11 20:20:09 · 1087 阅读 · 1 评论 -
【矩阵快速幂】POJ 3070 Fibonacci (大数 Fibonacci)(大二版)
题目链接:click here~~题目大意:In the Fibonacci integer sequence, F0 = 0, F1 = 1, andFn = Fn − 1 + Fn − 2 forn ≥ 2. For example, the first ten terms of the Fibonacci sequence are:0, 1, 1, 2, 3,原创 2015-04-09 19:47:05 · 1074 阅读 · 0 评论 -
【矩阵快速幂】HDU 4549 : M斐波那契数列(矩阵嵌套)
【题目链接】click here~~【题目大意】M斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 现在给出a, b, n,你能求出F[n]的值吗?对每组测试数据请输出一个整数F[n],由于F[n]可能很大,你只需输出F[n]对1000000007取模后的值即原创 2015-04-11 21:32:15 · 1112 阅读 · 0 评论 -
acdream 1060 递推数 (矩阵快速幂+循环节)
链接:click here~~题意:递推数Problem Description已知A(0) = 0 , A(1) = 1 , A(n) = 3 * A(n-1) + A(n-2) (n ≥ 2) 求 A(A(A(A(N)))) Mod (1e9 + 7)Input第一行一个整数 T (T ≤ 10000) 代表数据组数每组数据占一行,一个整数 n (1 ≤ n原创 2015-03-30 12:19:04 · 1263 阅读 · 0 评论 -
HDU 4291 A Short problem (2012成都网络赛,矩阵快速幂+循环节)
链接: click here~~题意:According to a research, VIM users tend to have shorter fingers, compared with Emacs users. Hence they prefer problems short, too. Here is a short one: Given n (1 18), Y原创 2015-03-30 12:31:23 · 1013 阅读 · 0 评论 -
矩阵快速幂模板
代码:#pragma comment (linker,"/STACK:102400000,102400000")#pragma comment (linker,"/STACK:102400000,102400000")#include #include #include #include #include #include #include #include #includ原创 2015-12-01 20:39:45 · 729 阅读 · 0 评论