poj 3420 Quad Tiling (状压dp+多米诺骨牌问题+矩阵快速幂)
还有这种操作??????
直接用pre到now转移的方式构造一个矩阵就好了。
二进制长度为m,就构造一个长度为1 << m的矩阵
最后输出ans[(1 << m) - 1][(1 << m) - 1]就好了
牛逼!
#include<cstdio>
#include<cstring>
#include<algorithm>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;
typedef long long ll;
const int MAXN = 16;
struct mat
{
   ll m[MAXN][MAXN];
   mat() { memset(m, 0, sizeof(m)); }
}A;
int n, MOD;
mat operator *(const mat& a, const mat& b)
{
	mat res;
	REP(i, 0, MAXN)
		REP(j, 0, MAXN)
			REP(k, 0, MAXN)
				res.m[i][j] = (res.m[i][j] + a.m[i][k] * b.m[k][j]) % MOD;
	return res;
}
void dfs(int l, int now, int pre)
{
	if(l > 4) return;
	if(l == 4)
	{
		A.m[pre][now]++;
		return;
	}
	dfs(l + 1, (now << 1) | 1, pre << 1);
	dfs(l + 1, now << 1, (pre << 1) | 1);
	dfs(l + 2, (now << 2) | 3, (pre << 2) | 3);
}
mat pow(mat a, int b)
{
	mat res;
	REP(i, 0, MAXN) res.m[i][i] = 1;
	for(; b; b >>= 1)
	{
		if(b & 1) res = res * a;
		a = a * a;
	}
	return res;
}
int main()
{
	dfs(0, 0, 0);
	while(~scanf("%d%d", &n, &MOD) && n)
	{
		mat ans = pow(A, n);
		printf("%lld\n", ans.m[15][15]);
	}
	return 0;
}poj 3420 Quad Tiling (状压dp+多米诺骨牌问题+矩阵快速幂)的更多相关文章
- CCF 201312-4	有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)
		问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ... 
- poj2411 Mondriaan's Dream (状压dp+多米诺骨牌问题)
		这道题的解析这个博客写得很好 https://blog.csdn.net/shiwei408/article/details/8821853 大致意思就是我们可以只处理两行之间的关系,然后通过这两个关 ... 
- poj 2663 Tri Tiling (状压dp+多米诺骨牌问题+滚动数组反思)
		本来直接一波状压dpAC的 #include<cstdio> #include<cstring> #include<algorithm> #define REP(i ... 
- POJ 3254 Corn Fields (状压dp)
		题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ... 
- POJ 3254 - Corn Fields - [状压DP水题]
		题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ... 
- [POJ 3420] Quad Tiling
		Quad Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3495 Accepted: 1539 Des ... 
- [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp
		题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ... 
- poj 3254Corn Fields (入门状压dp)
		Farmer John has purchased a lush ≤ M ≤ ; ≤ N ≤ ) square parcels. He wants to grow some yummy corn fo ... 
- POJ 1684 Corn Fields(状压dp)
		描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ ... 
随机推荐
- 03.IO读写-1.IO介绍
			1 文件操作介绍 in: 输入,读入.从硬盘中读到内存 out: 输出.从内存写到硬盘 文件的作用: 数据存储 2 文件的打开与关闭 2.1 打开文件 在Python,使用open函数,可以打开一个已 ... 
- poj  1611  简单并查集的应用
			#include<stdio.h> #define N 31000 int pre[N]; int find(int x) { if(x!=pre[x]) pre[x]=find( ... 
- servlet详细理解
			生命周期 编辑 客户端请求该 Servlet: 加载 Servlet 类到内存: 实例化并调用init()方法初始化该 Servlet: service()(根据请求方法不同调用doGet() 或者 ... 
- UFLDL教程笔记及练习答案五(自编码线性解码器与处理大型图像**卷积与池化)
			自己主动编码线性解码器 自己主动编码线性解码器主要是考虑到稀疏自己主动编码器最后一层输出假设用sigmoid函数.因为稀疏自己主动编码器学习是的输出等于输入.simoid函数的值域在[0,1]之间,这 ... 
- [Oracle] - Connect to a PDB of Oracle12c
			Story about CDB and PDB Oracle12c has a new feature and definition of CDB and PDB. If you first use ... 
- 【Java集合源代码剖析】LinkedList源代码剖析
			转载请注明出处:http://blog.csdn.net/ns_code/article/details/35787253 您好.我正在參加CSDN博文大赛.假设您喜欢我的文章,希望您能帮我投一票,谢 ... 
- c7---函数
			// // main.c // 函数练习 // // Created by xiaomage on 15/6/7. // Copyright (c) 2015年 xiaomage. All right ... 
- DB-MySQL:MySQL 处理重复数据
			ylbtech-DB-MySQL:MySQL 处理重复数据 1.返回顶部 1. MySQL 处理重复数据 有些 MySQL 数据表中可能存在重复的记录,有些情况我们允许重复数据的存在,但有时候我们也需 ... 
- No changes detected  or App 'blog' could not be found. Is it in INSTALLED_APPS?
			出现该问题的原因: django没有在setting.py的配置文件中找到app内容,需要增加app的名称 E:\PycharmProjects\Mysite>python manage.py ... 
- 使用log4net记录日志到数据库(含自定义属性)
			日志输出自定义属性! 特来总结一下: 一.配置文件 使用log4写入数据库就不多说了,网上方法很多,自定义字段如下 <commandText value="INSERT INTO db ... 
