#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. [SNOI 2017] 炸弹

    题目描述: 给定炸弹和爆炸范围,求对于每个炸弹连锁爆炸的炸弹总和对\(1e9+7\)取膜 思路: 为啥都是线段树+TS+tarjan呢? 实在是搞不懂~~ 线性\(O(n)\)递推即可. #inclu ...

  2. win 安装composer (详细教程)

    Composer是PHP的一个依赖管理工具,申明项目所依赖的代码库,它会在项目中为你安装,所以在实际项目开发中很方便,那么如何安装呢?今天就与大家分享下. 1首先下载好Composer,文件为exe类 ...

  3. char类型在传参时接收不到数据的原因

    mybatis的原因!!!!! 数据库这个样子 在postman中调用接口:SQL select * from T_TRAIN_MARSHALLING where TRAIN_NUM is null ...

  4. springcloud系列15 bus的使用

    可以结合wekbbok进行通知: 将更新的代码进行点击就好:

  5. 2018-8-10-使用-ahk-让普通键盘变为Dvorak键盘

    title author date CreateTime categories 使用 ahk 让普通键盘变为Dvorak键盘 lindexi 2018-08-10 19:16:51 +0800 201 ...

  6. Array.prototype.splice()

    splice() 方法通过删除或替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容.此方法会改变原数组. 在1位置上添加一项 我们没有下标为4的项,这个超了,就在最大项后面添加这 ...

  7. 新安装一个eclipse,导入一个web项目,右键点击项目选择Properties,找不到project facets和Server选项。

    解决方式: 1.点击:eclipse导航栏中点击Help->Install New Software 2.点击Add添加 3在弹出框中填写以下信息 name:keep(名字随便取) locati ...

  8. day3-编码、文件、集合、函数、递归

    学习内容: 1. 文件编码 2. 文件 3. 集合 4.函数 5.递归 6.匿名函数 1. 文件编码: 常见的字符串编码有:ASCII 扩展的ASCII Unicode GBK GB2312 GB18 ...

  9. eval()方法与str()方法

    eval()方法与str()方法 #_author:Administrator#date:2019/10/31 a={ 'q':{'xxx':3456}}#将一个字典转换成一个字符串a=str(a)p ...

  10. ArrayList去除重复元素(多种方法实现)

    package other; import java.util.ArrayList; import java.util.HashSet; public class test4 { public sta ...