Blocks

设涂到第I块时,颜色A,B都为偶数的数量为ai,一奇一偶的数量为bi,都为奇数为ci,  那么涂到第i+1快时有

a[i+1]=2*a[i]+b[i]+0*c[i];

b[i+1]=2*a[i]+2*b[i]+2*c[i];

C[i+1]=0*a[i]+b[i]+2*c[i];

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long LL;
const int INF=0x4fffffff;
const double EXP=1e-;
const int MS=;
const int SIZE=; const int mod=; typedef vector<vector<int> > mat; // calc A*B mat mul(mat &A,mat &B)
{
mat C(A.size(),vector<int>(B[].size())); for(int i=;i<A.size();i++)
{
for(int k=;k<B.size();k++)
{
for(int j=;j<B[].size();j++)
{
C[i][j]=(C[i][j]+(LL)A[i][k]*B[k][j])%mod; // note overflow
}
}
}
return C;
} // calc A^n mat pow(mat A,LL n)
{
mat B(A.size(),vector<int>(A[].size()));
for(int i=;i<A.size();i++)
B[i][i]=;
while(n>)
{
if(n&)
B=mul(B,A);
A=mul(A,A);
n>>=;
}
return B;
} LL n;
void solve()
{
mat A(,vector<int>());
A[][]=;A[][]=;A[][]=;
A[][]=;A[][]=;A[][]=;
A[][]=;A[][]=;A[][]=;
A=pow(A,n);
printf("%d\n",A[][]);
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
solve();
}
return ;
}

Blocks 推出矩阵公式。矩阵快速密的更多相关文章

  1. Luogu T7152 细胞(递推,矩阵乘法,快速幂)

    Luogu T7152 细胞(递推,矩阵乘法,快速幂) Description 小 X 在上完生物课后对细胞的分裂产生了浓厚的兴趣.于是他决定做实验并 观察细胞分裂的规律. 他选取了一种特别的细胞,每 ...

  2. 矩阵乘法&矩阵快速幂&矩阵快速幂解决线性递推式

    矩阵乘法,顾名思义矩阵与矩阵相乘, 两矩阵可相乘的前提:第一个矩阵的行与第二个矩阵的列相等 相乘原则: a b     *     A B   =   a*A+b*C  a*c+b*D c d     ...

  3. Luogu 3390 【模板】矩阵快速幂 (矩阵乘法,快速幂)

    Luogu 3390 [模板]矩阵快速幂 (矩阵乘法,快速幂) Description 给定n*n的矩阵A,求A^k Input 第一行,n,k 第2至n+1行,每行n个数,第i+1行第j个数表示矩阵 ...

  4. poj3613:Cow Relays(倍增优化+矩阵乘法floyd+快速幂)

    Cow Relays Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7825   Accepted: 3068 Descri ...

  5. AcWing 206. 石头游戏 矩阵乘法|矩阵快速幂

    AcWing 206. 石头游戏 石头游戏在一个 n 行 m 列 (1≤n,m≤8) 的网格上进行,每个格子对应一种操作序列,操作序列至多有10种,分别用0~9这10个数字指明. 操作序列是一个长度不 ...

  6. POJ3233不错的矩阵(矩阵套矩阵)

    题意:        给一个n*n的矩阵A,然后求S=A + A^2 + A^3 + ..+ A^k. 思路:       矩阵快速幂,这个题目挺新颖的,以往的矩阵快速幂都是退出公式,然后构造矩阵,这 ...

  7. hdu 1588 Gauss Fibonacci(矩阵嵌矩阵)

    题目大意: 求出斐波那契中的 第 k*i+b 项的和. 思路分析: 定义斐波那契数列的矩阵 f(n)为斐波那契第n项 F(n) = f(n+1) f(n) 那么能够知道矩阵 A = 1 1 1  0 ...

  8. C++题解:Matrix Power Series ——矩阵套矩阵的矩阵加速

    Matrix Power Series r时间限制: 1 Sec 内存限制: 512 MB 题目描述 给定矩阵A,求矩阵S=A^1+A^2+--+A^k,输出矩阵,S矩阵中每个元都要模m. 数据范围: ...

  9. Python 矩阵与矩阵以及矩阵与向量的乘法

    import numpy as np numpy模块的array相乘时,有两种方式:一是矩阵形式,二是挨个相乘. 需要用矩阵形式相乘时,则要用np.dot()函数. #矩阵与矩阵相乘a = np.ar ...

  10. POJ - 3233 矩阵套矩阵

    题意:给你矩阵\(A\),求\(S=\sum_{i=1}^{k}A^i\) 构造矩阵 \[ \begin{bmatrix} A & E \\ 0 & E\\ \end{bmatrix} ...

随机推荐

  1. Struts – Wildcards example

    Struts wildcards can helps to reduce the repetition in your struts-config.xml file, as long as your ...

  2. c语言指针详解(转载)

    转自(http://blog.csdn.net/ad_ad_ad/article/details/1522145) 指针是C语言中广泛使用的一种数据类型. 运用指针编程是C语言最主要的风格之一.利用指 ...

  3. 网页布局:float与position的区别

    网页开发中布局是一个永恒的话题.巧妙的布局会让网页具有良好的适应性和扩展性.css的布局主要涉及两个属性——position和float.它们俩看上去很容易被弄混,可是仔细分析一下,它们的区别还是很明 ...

  4. Ruby学习资源汇总

    from:http://segmentfault.com/a/1190000000362058 Ruby 语言 Try Ruby: 无需在你的系统中安装.Ruby,只要通过浏览器便可立即体验 Ruby ...

  5. Spring 常用工具类

    1) 请求工具类 org.springframework.web.bind.ServletRequestUtils //取请求参数的整数值: public static Integer getIntP ...

  6. javaScript 获取主机地址,项目名等

    //获取当前网址  var curWwwPath=window.document.location.href; alert(curWwwPath);  //http://localhost:8080/ ...

  7. Android 通过xml 自定义图片

    <?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http:/ ...

  8. JSP页面上用横线代替文本框

    <tr> <td class="content" colspan = 4> <input type="hidden" name=& ...

  9. C++ Bit Fields

    http://msdn.microsoft.com/en-us/library/ewwyfdbe%28v=vs.71%29.aspx Note An unnamed bit field of widt ...

  10. constraint使用方法总结

    主要就是添加约束的 下面几种约束 .并 一一列举: 1.主键约束: 要对一个列加主键约束的话,这列就必需要满足的条件就是分空 由于主键约束:就是对一个列进行了约束,约束为(非空.不反复) 下面是代码  ...