题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Google Codejam Round 1A的C题. #include <bits/stdc++.h> typedef long long ll; const int N = 5; int a, b, n, mod; /* *矩阵快速幂处理线性递推关系f(n)=a1f(n-1)+a2f(n-2)+.…
[解题思路] 给一张神图,推理写的灰常明白了,关键是构造共轭函数,这一点实在是要有数学知识的理论基础,推出了递推式,接下来就是矩阵的快速幂了. 神图: 给个大神的链接:构造类斐波那契数列的矩阵快速幂 /* * Problem: HDU No.4565 * Running time: 62MS * Complier: G++ * Author: javaherongwei * Create Time: 9:55 2015/9/21 星期一 */ #include <bits/stdc++.h>…
http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1475    Accepted Submission(s): 539 Problem Description Let us define a sequence as belo…
A Short problem Problem's Link Mean: 给定一个n,求:g(g(g(n))) % 1000000007 其中:g(n) = 3g(n - 1) + g(n - 2),g(1) = 1,g(0) = 0 analyse: 很经典的题.由于n特别大,直接求肯定不行.由于所有的模运算都会出现循环节,可以求出循环节. 由于模数是固定的,可以在本地暴力求出循环节. 对于1000000007,求得循环节为222222224: 对于222222224,求得循环节183120:…
Problem Description Little Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of multiple red and blue beads. Little Q desperately wants to impress his girlfriend, he knows that she will like the necklace only if for…
题目链接:传送门 题目: Recursive sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description Farmer John likes to play mathematics games with his N cows. Recently, they are attracted…
http://acm.hdu.edu.cn/showproblem.php?pid=2256 题意:给定 n    求解   ? 思路: , 令  , 那么 , 得: 得转移矩阵: 但是上面求出来的并不是结果,并不是整数.需要加上, 由于 所以结果为 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using namespace std; #define rep0…
太妙了..通过矩阵乘法来加速递推 #include<iostream> #include<cstring> #include<cstdio> using namespace std; #define mod 10000 int n; ][]){//一维数组和矩阵相乘 ]={}; ;i<;i++) ;j<;j++) c[j]=(c[j]+(long long)f[i]*a[i][j])%mod; memcpy(f,c,sizeof c); } ][]){//矩…
题意:给你矩阵A,求S=A+A^1+A^2+...+A^n sol:直接把每一项解出来显然是不行的,也没必要. 我们可以YY一个矩阵: 其中1表示单位矩阵 然后容易得到: 可以看出这个分块矩阵的左下角那块就可以得到要求的解S 我们取这一块,再减去一个单位矩阵1即可. 为了保持右下角一直是1,所以右上的位置必须是0,由于需要不断移位,所以1是必要的,A是必要的,所以第一列保证移位, 第二列保证保留1,因此我们能成功构造出.... 这个题还可以根据等比矩阵的性质来进行求解...后面补(x 1 #in…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4565 题目大意: 给出a,b,n,m,求出的值, 解题思路: 因为题目中出现了开根号,和向上取整后求余,所以用矩阵快速幂加速求解过程的时候,会产生误差,就很自然地想到了凑数,因为(a-1)^2<b<a^2,得出0<a-sqrt(b)<1,则无论n取多大,(a-sqrt(b))^n都是小于1的,(a-sqrt(b))^n 与 (a+sqrt(b))^n共轭,两者展开后会相互抵销,所以(…