
矩阵快速幂
文章平均质量分 62
ehi11
这个作者很懒,什么都没留下…
展开
-
poj 3233 Matrix Power Series 矩阵快速幂
/*愧疚了,好久没写什么有意思的题了。 这道基于二分的矩阵连乘,方法很经典。 求幂二分,求和再二分。经典。 求幂的时候,若奇数,A^n=A^(n/2)*A^(n/2)*A. 偶数时 A^n=A^(n/2)*A^(n/2)。 求和的时候,若为奇数,A^1+A^2+...+A^(2*m+1)=(A^1+...+A^m)+(A^1+...+A^m)*A^m*A, 若为偶数 A^1+A^2+...+A^原创 2012-09-12 21:32:44 · 879 阅读 · 0 评论 -
How many ways?? hdu 2157
#include #include #include using namespace std; int tmp[21][21],ans[21][21],b[21][21]; int N; void mul(int a[][21],int b[][21]) { memset(tmp,0,sizeof(tmp)); for(int i=1; i<=N; i++)原创 2013-02-27 11:01:24 · 923 阅读 · 0 评论 -
hoj 2060 Fibonacci Problem Again
#include #include #include #define mod 1000000000 using namespace std; typedef long long LL; LL a[4][4],tmp[4][4],ans[4][4]; void mul(LL a[][4],LL b[][4]) { for(int i=1; i<=4; i++) for(原创 2013-02-27 10:57:10 · 754 阅读 · 0 评论 -
A Simple Math Problem hdu 1757
#include #include #include using namespace std; typedef long long LL; LL tmp[11][11],a[11][11],b[11][11]; int mod; void mul(LL a[][11],LL b[][11]) { for(int i=0; i<10; i++) for(int j=0;原创 2013-02-27 11:00:29 · 929 阅读 · 0 评论 -
Weights hoj 2635
#include #include #define mod 9999997 long long tmp[3][3],ans[3][3],a[3][3]; void mul(long long a[][3],long long b[][3]) { for(int i=1; i<=2; i++) for(int j=1; j<=2; j++) {原创 2013-02-27 10:58:11 · 646 阅读 · 0 评论 -
hoj 2255 Not Fibonacci
#include #include #include #define mod 10000000 using namespace std; typedef long long LL; LL a[4][4],tmp[4][4],ans[4][4]; void mul(LL a[][4],LL b[][4]) { for(int i=1; i<=3; i++) for(in原创 2013-02-24 13:03:29 · 755 阅读 · 0 评论 -
Fibonacci Numbers hoj 求斐波那契前四位和后四位
#include #include #include #include #define c (sqrt(5.0)+1.0)/2.0 #define mod 10000 using namespace std; typedef long long LL; LL tmp[3][3],a[3][3],ans[3][3]; void mul(LL a[][3],LL b[][3]) { f原创 2013-02-24 13:05:20 · 863 阅读 · 0 评论 -
Number Sequence hdu 构造矩阵乘法
/*题目所给的a,b和f的初始值很重要。 一次来确定矩阵的元素和幂。 [a b1 0]×[f(n−1)f(n−2)]=[f(n)f(n−1)] [a b1 0]n−2×[11]=[f(n)f(n−1)] 因为f[1]=1,f[2]=1, 所以递推到n-2次幂,间接矩阵为1,1. 如果初始条件改变的话,次幂也间接矩阵也会随之改变。 要灵活应用。*/ #include #include const原创 2012-09-22 09:00:28 · 924 阅读 · 0 评论 -
Fibonacci hoj 矩阵快速幂裸题
#include #include const int mod=10000; int A[3][3],ans[3][3]; void mul(int a[][3],int b[][3]) { int tmp[3][3]; for(int i=1; i<=2; i++) for(int j=1; j<=2; j++) { t原创 2012-09-13 16:06:00 · 720 阅读 · 0 评论 -
多校 4686 Arc of Dream hdu 矩阵解
构造矩阵如下: Ai*bi AX*BX AX*BY AY*BX AY*BY 0 a(i-1)*b(i-1) Ai 0 AX 0 AY 0 a(i-1) Bi原创 2013-08-20 18:09:31 · 1274 阅读 · 1 评论