矩阵快速幂2 3*n铺方格
#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铺方格的更多相关文章
- 矩阵快速幂3 k*n铺方格
#include <iostream> #include <cstdlib> #include <cstring> #include <queue> # ...
- 瓷砖铺放 (状压DP+矩阵快速幂)
由于方块最多涉及3行,于是考虑将每两行状压起来,dfs搜索每种状态之间的转移. 这样一共有2^12种状态,显然进行矩阵快速幂优化时会超时,便考虑减少状态. 进行两遍bfs,分别为初始状态可以到达的状态 ...
- 51nod 1122 机器人走方格 V4 【矩阵快速幂】
首先建立矩阵,给每个格子编号,然后在4*4的格子中把能一步走到的格子置为1,然后乘n次即可,这里要用到矩阵快速幂 #include<iostream> #include<cstdio ...
- CH3401 石头游戏(矩阵快速幂加速递推)
题目链接:传送门 题目: 石头游戏 0x30「数学知识」例题 描述 石头游戏在一个 n 行 m 列 (≤n,m≤) 的网格上进行,每个格子对应一种操作序列,操作序列至多有10种,分别用0~9这10个数 ...
- hdu 6185 递推+【矩阵快速幂】
<题目链接> <转载于 >>> > 题目大意: 让你用1*2规格的地毯去铺4*n规格的地面,告诉你n,问有多少种不同的方案使得地面恰好被铺满且地毯不重叠.答案 ...
- CH 3401 - 石头游戏 - [矩阵快速幂加速递推]
题目链接:传送门 描述石头游戏在一个 $n$ 行 $m$ 列 ($1 \le n,m \le 8$) 的网格上进行,每个格子对应一种操作序列,操作序列至多有 $10$ 种,分别用 $0 \sim 9$ ...
- POJ 3734 Blocks (矩阵快速幂)
题目链接 Description Panda has received an assignment of painting a line of blocks. Since Panda is such ...
- HDU - 6185 Covering(暴搜+递推+矩阵快速幂)
Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...
- wiki with 35(dp+矩阵快速幂)
Problem J. Wiki with 35Input file: standard input Time limit: 1 secondOutput file: standard output M ...
随机推荐
- 概率dp——期望水题hdu4405
还是逆推,如果遇到跳板直接继承目标地的期望即可 #include<bits/stdc++.h> using namespace std; #define maxn 200005 doubl ...
- Maven Projects报错但对应的pom文件不报错解决方案
情景:dependencies中总有红波浪线报错,但是核对包名和路径,以及pom文件没有任何问题 项目可以正常运行,这种时候有强迫症的就不行了.... 解决方案是,根据波浪线提示的jar包,到pom文 ...
- Git 查看、删除、重命名远程分支
原文地址:http://blog.csdn.net/sunnyyoona/article/details/52065544 1. 查看远程分支 分支加上-a参数可以查看远程分支,远程分支会用红色表示出 ...
- Identifying a Blocking Query After the Issuing Session Becomes Idle
Identifying a Blocking Query After the Issuing Session Becomes Idle #查看阻塞信息 select * from sys.innodb ...
- Searching the String ZOJ - 3228 AC自动机查询升级版
题意:先给你一个不超过1000000长度的大串s:接下来输入一个n代表接下来输入的小串个数,小串长度不超过6. 小串分两种类型0和1类型. 0类型表示小串在大串中的最大匹配个数就是常规的AC自动机的做 ...
- CAS机制详解
目录 1. 定义 2. 实现原理 3. 无版本号CAS实战说明 4. CAS机制在Java中的应用 5. CAS的缺点 1. CPU开销过大 2. 不能保证代码块的原子性 3. ABA问题 6. JA ...
- (转)打开Mac OSX原生的NTFS功能
xingchongsmbp3:~ xingchong$ xingchongsmbp3:~ xingchong$ xingchongsmbp3:~ xingchong$ sudo ln -s /Volu ...
- 2.初始化spark
参考: RDD programming guide http://spark.apache.org/docs/latest/rdd-programming-guide.html SQL progr ...
- 关于underline
1, 有些系统可能看不到下划线的效果,这是不妨按着Alt键看看: 2, underline=#, 数字表示在哪个字母下显示下划线,从0开始
- ST(RMQ)算法(在线)求LCA
在此之前,我写过另一篇博客,是倍增(在线)求LCA.有兴趣的同学可以去看一看.概念以及各种暴力就不在这里说了,那篇博客已经有介绍了. 不会ST算法的同学点这里 ST(RMQ)算法在线求LCA 这个算法 ...