#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; const int MOD = ; struct Martix
{
LL martix[][];
int row,col;
Martix(int _row,int _col)
{
memset(martix,,sizeof(martix));
row = _row;
col = _col;
}
void sets(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]);
if(C.martix[i][j] >= MOD)
C.martix[i][j]%=MOD;
} return C;
}
}; //
//第i行不放置:new_x = x << 1, new_y = (y << 1) + 1; 列数+1
//第i行竖放骨牌:new_x = (x << 1) + 1, new_y = y << 1; 列数+1
//第i行横向骨牌:new x = (x << 2) + 3, new_y = (y << 2) + 3; 列数+2 int k;
Martix A(,),F(,);
void dfs(int x,int y,int col)
{
if(col == k) {A.martix[y][x] = ; return ;}
dfs(x<<, (y<<) + , col+);
dfs( (x<<) + , y << , col + );
if(col + <= k)
dfs( (x << )+ , (y << )+, col+);
} void solve()
{
int n;
scanf("%d %d",&k,&n);
if( (k&) && (n&) )
{
printf("%d\n",);
return ;
}
A.sets(<<k,<<k);
F.sets(<<k,<<k);
dfs(,,);
for(int i = ; i < (<<k); i++)
F.martix[i][i] = ;
while(n > )
{
if(n & )
F = F*A;
A = A*A;
n >>= ;
}
printf("%lld\n",F.martix[ (<<k)- ][ (<<k)- ]);
} int main(void)
{
solve();
return ;
}

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

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

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

  2. hdu 6198(矩阵快速幂)

    number number number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. NOI ONLINE 入门组 魔法 矩阵快速幂

    做了这道题我才发现NOI入门组!=NOIP普及组 题目链接 https://www.luogu.com.cn/problem/P6190 题意 给出一张有向图,你有K次机会可以反转一条边的边权,即让它 ...

  4. poj 3613 经过k条边最短路 floyd+矩阵快速幂

    http://poj.org/problem?id=3613 s->t上经过k条边的最短路 先把1000范围的点离散化到200中,然后使用最短路可以使用floyd,由于求的是经过k条路的最短路, ...

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

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

  6. hdu 2157 从a点走到b点刚好k步的方案数是多少 (矩阵快速幂)

    n个点 m条路 询问T次 从a点走到b点刚好k步的方案数是多少 给定一个有向图,问从A点恰好走k步(允许重复经过边)到达B点的方案数mod p的值把 给定的图转为邻接矩阵,即A(i,j)=1当且仅当存 ...

  7. hdu 1575 求一个矩阵的k次幂 再求迹 (矩阵快速幂模板题)

    Problem DescriptionA为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973. Input数据的第一行是一个T,表示有T组数据.每组数据的第一行有 ...

  8. poj3613Cow Relays——k边最短路(矩阵快速幂)

    题目:http://poj.org/problem?id=3613 题意就是求从起点到终点的一条恰好经过k条边的最短路: floyd+矩阵快速幂,矩阵中的第i行第j列表示从i到j的最短路,矩阵本身代表 ...

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

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

随机推荐

  1. SpringBoot2.0+ 使用Log4j2日志输出

    据说Log4j2相比log4j效率有很大提升. pom.xml导入 <dependency> <groupId>org.springframework.boot</gro ...

  2. tomcat7 linux service

    1. 创建tomcat用户 useradd -r -m -d /usr/local/tomcat7 -s /sbin/nologin tomcat 2. 将下面脚本命名为tomcat7 放入/etc/ ...

  3. 国外主机如何ICP备案

    想都不要想了,无法备案. 因为,备案是在主机服务器提供商处的备案平台提交申请,国外的主机服务商是没有这种平台服务的.(跟你域名在哪儿买的没关系) 下面,把昨天折腾到半夜的过程记录一下,希望可以帮到需要 ...

  4. 在core2.0中实现按程序集注入依赖

    前言:在Autofac的使用中,提供了个种注入的API其中GetAssemblies()用着特别的舒坦. 1.core2.0也可以使用Autofac的包,但框架自身也提供了默认的注入Api,IServ ...

  5. C#窗体代码相关笔记

    获取ComboBox下拉列表的所有选项值 ArrayList al = new ArrayList(); foreach (string item in this.comboBox2.Items) { ...

  6. Luogu P1039 侦探推理(模拟+枚举)

    P1039 侦探推理 题意 题目描述 明明同学最近迷上了侦探漫画<柯南>并沉醉于推理游戏之中,于是他召集了一群同学玩推理游戏.游戏的内容是这样的,明明的同学们先商量好由其中的一个人充当罪犯 ...

  7. angularjs 1 Failed to read the 'selectionStart' property from 'HTMLInputElement':

    在找angularjs input(type='number')在获取焦点的时候,文本框内容选中效果,参考了:Select text on input focus,我直接复制他的code之后,在ion ...

  8. xcart-子分类/语言不显示

    由于数据库的版本不同,表名会区分大小写的情况,这样就导致xcart语言相关的信息显示不出来,此时只需更改根目录下的init.php文件,如下: 改成小写的就OK了.

  9. MongDB4.0-入门学习之运算符

    MongDB 4.0 入门学习之运算符 基本语法:db.collection.find({<key>:{$symbol:<value>}}) 条件查询匹配运算符 符号 描述 范 ...

  10. 容斥原理——hdu2841

    记得要开ll /* 莫比乌斯反演模板题,也可以直接算phi来做 容斥的解法 求x[1..m],在[1,n]中和其互质的数的个数即可 那么就是n-和x不互质的数个数即可 */ #include<b ...