Blocks(POJ 3734 矩阵快速幂)】的更多相关文章

题目原意:N个方块排成一列,每个方块可涂成红.蓝.绿.黄.问红方块和绿方块都是偶数的方案的个数. sol:找规律列递推式+矩阵快速幂 设已经染完了i个方块将要染第i+1个方块. a[i]=1-i方块中,红.绿方块数量都是偶数的方案数 b[i]=1-i方块中,红.绿方块数量一个是偶数一个是奇数的方案数(红even绿odd 或 红odd绿even) c[i]=1-i方块中,红.绿方块数量都是奇数的方案数 可以得出递推公式: a[i+1]=2*a[i]+b[i] b[i+1]=2*a[i]+2*b[i…
Blocks Input The first line of the input contains an integer T(1≤T≤100), the number of test cases. Each of the next T lines contains an integer N(1≤N≤10^9) indicating the number of blocks. Output For each test cases, output the number of ways to pain…
地址 http://poj.org/problem?id=3233 大意是n维数组 最多k次方  结果模m的相加和是多少 Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak. Sample Input 2 2 4 0 1 1 1 Sample Output 1 2 2 3 题解 矩阵逐步的相乘然后相加是不可以 但是矩阵也有类似快速幂的做法 /*A + A^2 =A(I+A)…
矩阵快速幂:http://www.cnblogs.com/atmacmer/p/5184736.html 题目链接 #include<iostream> #include<cstdio> using namespace std; typedef long long ll; #define MOD 10000 ll a[],b[],a0[],b0[]; void pow_mod(ll n) { a0[]=a0[]=a0[]=,a0[]=; b0[]=b0[]=,b0[]=b0[]=;…
2017-09-13 19:22:01 writer:pprp 题意很简单,就是通过矩阵快速幂进行运算,得到斐波那契数列靠后的位数 . 这是原理,实现部分就是矩阵的快速幂,也就是二分来做 矩阵快速幂可以用来解决线性递推方程,难点在于矩阵的构造 代码如下: /* @theme:用矩阵快速幂解决线性递推公式-斐波那契数列 @writer:pprp @begin:21:17 @end:19:10 @error:注意mod的位置,不能连用,要加括号来用 @date:2017/9/13 */ #inclu…
题意:求菲波那切数列的第n项. 分析:矩阵快速幂. 右边的矩阵为a0 ,a1,,, 然后求乘一次,就进一位,求第n项,就是矩阵的n次方后,再乘以b矩阵后的第一行的第一列. #include <cstdio> #include <cstring> using namespace std; typedef long long ll; ; ; struct Matrix { int n,m; int a[maxn][maxm]; void clear() { n = m = ; mems…
题意: 给你一个n*n的矩阵 让你求S: 思路: 只知道矩阵快速幂 然后nlogn递推是会TLE的. 所以呢 要把那个n换成log 那这个怎么搞呢 二分! 当k为偶数时: 当k为奇数时: 就按照这么搞就能搞出来了 (我是看的题解才A的,,, 中间乱搞的时候犯了一些脑残的错误) // by SiriusRen #include <cstdio> #include <cstring> using namespace std; int n,mod,k; struct matrix{int…
题目大意: 输入n,代表一位童子兵要穿过一条路,路上有些地方放着n个地雷(1<=n<=10).再输入p,代表这位童子兵非常好玩,走路一蹦一跳的.每次他在 i 位置有 p 的概率走一步到 i+1 ,或者 (1-p) 的概率跳一步到 i+2.输入n个数,代表n个地雷的位置(1<=n<=100000000),童子兵初始在1位置,求他安全通过这条道路的概率. 基本思路: 如果k 号位有雷,那么安全通过这个雷只可能是在 k-1 号位选择走两步到 k+1 号位.因此,可以得到如下结论:在第 i…
题目链接  请猛戳~ Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak. Input The input contains exactly one test case. The first line of input contains three positive integers n (n ≤ 30), k (k ≤ 109) and m (m <…
题意:给你矩阵A,求S=A+A^1+A^2+...+A^n sol:直接把每一项解出来显然是不行的,也没必要. 我们可以YY一个矩阵: 其中1表示单位矩阵 然后容易得到: 可以看出这个分块矩阵的左下角那块就可以得到要求的解S 我们取这一块,再减去一个单位矩阵1即可. #include "iostream" #include "vector" #include "cstring" #include "cstdio" using…