#include <iostream>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <map>
#include <time.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define LL long long using namespace std;
using namespace __gnu_pbds; //U[n]表示3×N棋盘的摆放数,
//
//V[n]表示缺了1×1边角的3×N棋盘的摆放数
//
//则
//
//U[n] = 2*V[n-1] + U[n-2]
//
//V[n] = U[n-1] + V[n-2]
//
//其中,
//
//U[0] = 1, U[2] = 3;
//
//V[0] = 1, V[1] =1; //[U(n) [ 0 2 1 0 [ U(n-1)
// V(n) 1 0 0 1 V(n-1)
// U(n-1) = 1 0 0 0 * U(n-2)
// V(n-1)] 0 1 0 0 ] V(n-2) ]
//
// [ 0 2 1 0 [ U(1)
// = 1 0 0 1 V(1)
// 1 0 0 0 ^ (n-1) U(0)
// 0 1 0 0 ] V(0) ] const int MOD = ; struct Martix
{
LL martix[][];
int row,col;
Martix(int _row,int _col)
{
memset(martix,,sizeof(martix));
row = _row;
col = _col;
}
Martix operator *(const Martix &A)const
{
Martix C(row, A.col);
for(int i = ; i < row; i++)
for(int j = ; j < A.col; j++)
for(int k = ; k < col; k++)
C.martix[i][j] = (C.martix[i][j] + martix[i][k] * A.martix[k][j])%MOD;
return C;
}
}; void solve()
{
Martix A(,), F(,), S(,);
A.martix[][] = A.martix[][] = A.martix[][] = A.martix[][] = A.martix[][] = ;
F.martix[][] = F.martix[][] = F.martix[][] = F.martix[][] = ;
A.martix[][] = ;
S.martix[][] = S.martix[][] = S.martix[][] = ;
int n;
scanf("%d",&n);
if(n&)
{
printf("%d\n",);
return ;
}
n--;
while(n > )
{
if(n & )
F = F*A;
A = A*A;
n >>= ;
}
S = F*S;
printf("%lld\n",S.martix[][]);
} int main(void)
{
solve();
return ;
}

矩阵快速幂2 3*n铺方格的更多相关文章

  1. 矩阵快速幂3 k*n铺方格

    #include <iostream> #include <cstdlib> #include <cstring> #include <queue> # ...

  2. 瓷砖铺放 (状压DP+矩阵快速幂)

    由于方块最多涉及3行,于是考虑将每两行状压起来,dfs搜索每种状态之间的转移. 这样一共有2^12种状态,显然进行矩阵快速幂优化时会超时,便考虑减少状态. 进行两遍bfs,分别为初始状态可以到达的状态 ...

  3. 51nod 1122 机器人走方格 V4 【矩阵快速幂】

    首先建立矩阵,给每个格子编号,然后在4*4的格子中把能一步走到的格子置为1,然后乘n次即可,这里要用到矩阵快速幂 #include<iostream> #include<cstdio ...

  4. CH3401 石头游戏(矩阵快速幂加速递推)

    题目链接:传送门 题目: 石头游戏 0x30「数学知识」例题 描述 石头游戏在一个 n 行 m 列 (≤n,m≤) 的网格上进行,每个格子对应一种操作序列,操作序列至多有10种,分别用0~9这10个数 ...

  5. hdu 6185 递推+【矩阵快速幂】

    <题目链接> <转载于 >>> > 题目大意: 让你用1*2规格的地毯去铺4*n规格的地面,告诉你n,问有多少种不同的方案使得地面恰好被铺满且地毯不重叠.答案 ...

  6. CH 3401 - 石头游戏 - [矩阵快速幂加速递推]

    题目链接:传送门 描述石头游戏在一个 $n$ 行 $m$ 列 ($1 \le n,m \le 8$) 的网格上进行,每个格子对应一种操作序列,操作序列至多有 $10$ 种,分别用 $0 \sim 9$ ...

  7. POJ 3734 Blocks (矩阵快速幂)

    题目链接 Description Panda has received an assignment of painting a line of blocks. Since Panda is such ...

  8. HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

    Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...

  9. wiki with 35(dp+矩阵快速幂)

    Problem J. Wiki with 35Input file: standard input Time limit: 1 secondOutput file: standard output M ...

随机推荐

  1. Mysql中“select ... for update”排他锁(转)

    原帖地址 https://blog.csdn.net/claram/article/details/54023216 Mysql InnoDB 排他锁 用法: select … for update; ...

  2. vue mounted组件的使用

    1.钩子函数  钩子函数是Windows消息处理机制的一部分,通过设置“钩子”,应用程序可以在系统级对所有消息.事件进行过滤,访问在正常情况下无法访问的消息.钩子的本质是一段用以处理系统消息的程序,通 ...

  3. UVA-307-Sticks-dfs+剪枝

    George took sticks of the same length and cut them randomly until all parts became at most 50 units ...

  4. threading线程例子 (27-08)

    利用阻塞的时间空闲去执行另一个子线程 import threading from time import ctime, sleep def music(func): for i in range(2) ...

  5. java.nio.file.FileSystemException: D:\kafka_2.12-2.1.0\kafka_2.12-2.1.0\logs\__consumer_offsets-30\00000000000000000000.timeindex.cleaned: 另一个程序正在使用此文件,进程无法访问。

    在启动kafka时候报错: java.nio.file.FileSystemException: D:\kafka_2.12-2.1.0\kafka_2.12-2.1.0\logs\__consume ...

  6. 使用CEfSharp之旅(5)CEFSharp 隔离Cookie

    原文:使用CEfSharp之旅(5)CEFSharp 隔离Cookie 版权声明:本文为博主原创文章,未经博主允许不得转载.可点击关注博主 ,不明白的进群191065815 我的群里问 https:/ ...

  7. 线性回归代码实现(matlab)

    1 代价函数实现(cost function) function J = computeCost(X, y, theta) %COMPUTECOST Compute cost for linear r ...

  8. [NOIP2019模拟赛]LuoguP4261白金元首与克劳德斯

    题目描述 给出坐标系中n个矩形,类型1的矩形每单位时间向x轴正方向移动1个单位,类型2的矩形向y轴正方向,初始矩形不重叠,一个点被矩形覆盖当且仅当它在矩形内部(不含边界),求$(-\infty ,+\ ...

  9. show master status

    只有在主库上执行才能有效抵输出: 具体文档如下: # 在127.:3306主库上执行 tmp@127.0.0.1 ((none))> show variables like '%server%' ...

  10. SpringBoot配置自定义日期参数转换器

    1.自定义参数转换器 自定义参数转换器必须实现Converter接口 /** * Created by IntelliJ IDEA. * * @Auther: ShaoHsiung * @Date: ...