#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. 概率期望——cf round362 div1

    给定n个数,求i的位置的期望 那么反向考虑,j!=i排在i前面的概率是0.5,那么对i的位置的期望贡献就是1*0.5 这题就是拓展应用一下 #include<bits/stdc++.h> ...

  2. 尚学python课程---13、python基础语法

    尚学python课程---13.python基础语法 一.总结 一句话总结: legend2系统使我能够快速掌握一门语法,特别有用 pass 语句:空语句:是为了保持程序结构的完整性  :作用:比如: ...

  3. c# 中Linq Lambda 的ToLookup方法的使用

    同样直接上代码: List<Student> ss = new List<Student>(); Student ss1 = , Age = , Name = " } ...

  4. x-杂项-maven-repository-lombok:lombok

    ylbtech-杂项-maven-repository-lombok:lombok Project Lombok是一个java库,可以自动插入编辑器并构建工具,为您的java增添色彩.永远不要再写另一 ...

  5. nodejs与websocket模拟简单的聊天室

    nodejs与websocket模拟简单的聊天室 server.js const http = require('http') const fs = require('fs') var userip ...

  6. 新建mapping

    新建索引: PUT logstash-redis-log-2017.12 PUT logstash-redis-log-2017.12/_mapping/redis-log  {       &quo ...

  7. 区间dp及优化

    看了下感觉区间dp就是一种套路,直接上的板子代码就好了. 基础题ac代码:石子归并 #include<bits/stdc++.h> using namespace std; typedef ...

  8. umount:将文件设备卸载

    [root@centos57 ~]# umount /dev/hda1 用设备文件名来卸载 [root@centos57 ~]# umount /aixi                     用挂 ...

  9. php socket模拟http中post或get提交数据

    php socket模拟http中post或者get提交数据的示例代码. 代码: sock_post.php: <?php /** * php socket模拟post\get请求 * 编辑:脚 ...

  10. display: -webkit-box; 做个小小试验

    最近做个微信项目发现css3在微信内部浏览器中和其他浏览有些区别 做个小小笔记 .job { display: -webkit-box; display: flexbox; -webkit-box-p ...