题目链接题意 : 用矩阵相乘求斐波那契数的后四位。思路 :基本上纯矩阵快速幂。 1 //3070 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 struct Matrix 9 {10 int v[2][2...
分类:
其他好文 时间:
2014-06-28 17:48:14
阅读次数:
214
2013年南京邀请赛的铜牌题。。。做的很是伤心,另外有两个不太好想到的地方。。。。a 可以等于零,另外a到b的累加和比较大,大约在2^70左右。
打表查规律比较神奇,上图不说话。
打表的代码
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pra...
分类:
其他好文 时间:
2014-06-22 21:12:01
阅读次数:
249
矩阵快速幂其实跟普通快速幂一样,只是把数换成矩阵而已。模板,两种写法,亲测可用://made by whatbeg//2014.6.15struct Matrix{ int m[3][3];};Matrix Mul(Matrix a,Matrix b){ Matrix c; mem...
分类:
其他好文 时间:
2014-06-18 22:35:45
阅读次数:
277
一些递推关系如f(n) = af(n-1)+bf(n-2)+...+tf(n-k)等,在n很大的时候,O(n)的算法都不能满足要求的时候,往往可以化为矩阵快速幂来做,复杂度可以降为O(logn),大大减少了运行时间。如何将一个递推关系式化为矩阵呢?比如这样一个递推关系: f(n) = 2*f(n-1...
分类:
其他好文 时间:
2014-06-18 20:54:04
阅读次数:
165
题目大意:
求刚好经过K条路的最短路
我们知道如果一个矩阵A[i][j] 表示表示 i-j 是否可达
那么 A*A=B B[i][j] 就表示 i-j 刚好走过两条路的方法数
那么同理
我们把i-j 的路径长度存到A 中。
在A*A的过程中,不断取小的,那么最后得到的也就是i - j 走过两条路的最短路了。
当然也是利用到了floyd的思想。
然后要...
分类:
其他好文 时间:
2014-06-16 20:50:53
阅读次数:
195
http://poj.org/problem?id=3150
大致题意:给出n个数,问经过K次变换每个位置上的数变为多少。第i位置上的数经过一次变换定义为所有满足 min( abs(i-j),n-abs(i-j) )
思路:
我们先将上述定义表示为矩阵
B =
1 1 0 0 1
1 1 1 0 0
0 1 1 1 0
0 0 1 1 1
1 0 0 1 1...
分类:
其他好文 时间:
2014-06-15 16:14:14
阅读次数:
169
Problem Description
give you a string, please output the result of the following function mod 1000000007
n is the length of the string
f() is the function of fibonacci, f(0) = 0, f(1) = 1...
a...
分类:
其他好文 时间:
2014-06-14 11:45:49
阅读次数:
243
http://poj.org/problem?id=3735
大致题意:
有n只猫,开始时每只猫有花生0颗,现有一组操作,由下面三个中的k个操作组成:
1. g i 给i只猫一颗花生米
2. e i 让第i只猫吃掉它拥有的所有花生米
3. s i j 将猫i与猫j的拥有的花生米交换
现将上述一组操作循环m次后,问每只猫有多少颗花生?
再一次感受到了...
分类:
其他好文 时间:
2014-06-14 10:54:33
阅读次数:
234
复杂度为o(n^3logk)
/*
求 a^k % mod,其中a是n*n的矩阵
*/
const int mod = 10000;
const int maxn = 2;
_LL k;
int n;
struct matrix
{
_LL mat[maxn][maxn];
} a,res;
matrix mul(matrix x, matrix y)
{
matrix tmp...
分类:
其他好文 时间:
2014-06-14 07:46:19
阅读次数:
206