【状压dp && 矩阵快速幂】 POJ
来源:互联网 发布:linux人 编辑:程序博客网 时间:2024/05/20 06:05
Problem Description
给你一个4×N的矩阵,你可以填1×2的矩阵 or 2×1的矩阵,问你填满有多少种方案,需要取mod。
思路:
poj 2411的基础上加了个矩阵快速幂
#include<cstdio>#include<cstring>using namespace std;struct node{ long long a[16][16];};node c;int n, mod;void dfs(int l, int now, int pre){ if(l > 4) return; if(l == 4) { c.a[pre][now]++; return ; } dfs(l + 2, (now<<2)|3, (pre<<2)|3); dfs(l + 1, now<<1, (pre<<1)|1); dfs(l + 1, (now<<1)|1, pre<<1);}node mul(node x, node y)//矩阵相乘{ node ans; int i, j, k; for(i = 0; i < 16; i++) { for(j = 0; j < 16; j++) { ans.a[i][j] = 0; for(k = 0; k < 16; k++) { ans.a[i][j] += x.a[i][k] * y.a[j][k]; ans.a[i][j] %= mod; } } } return ans;}node sm(node x, int m)//矩阵快速幂{ node ans; memset(ans.a, 0, sizeof(ans.a)); for(int i = 0; i < 16; i++) ans.a[i][i] = 1; while(m) { if(m & 1) ans = mul(ans, x); x = mul(x, x); m = m>>1; } return ans;}int main(){ while(~scanf("%d %d", &n, &mod)) { if(!n && !mod) break; if(mod == 1) {printf("0\n"); continue;} memset(c.a, 0, sizeof(c.a)); dfs(0, 0, 0); node ans = sm(c, n); printf("%lld\n", ans.a[15][15]); } return 0;}
阅读全文
0 0
- 【状压dp && 矩阵快速幂】 POJ
- POJ 3420 Quad Tiling 状压DP+矩阵快速幂
- poj 3420 Quad Tiling 状压dp+矩阵快速幂
- POJ 3744 概率dp+矩阵快速幂
- poj 2778 DNA Sequence 【ac自动机 + dp + 矩阵快速幂】
- poj 2778 AC自动机+DP+矩阵快速幂
- POJ 3744 Scout YYF I 矩阵快速幂加速dp
- poj 2778 (AC自动机+dp+矩阵快速幂)
- poj 3744 Scout YYF I(概率DP&矩阵快速幂)
- POJ 3734 —— 矩阵快速幂 + DP
- poj 3744 Scout YYF I(概率dp+矩阵快速幂)
- [AC自动机+dp+矩阵快速幂] poj 2778 DNA Sequence
- POJ 3744 Scout YYF I 概率DP + 矩阵快速幂
- poj 2778 ac自动机dp矩阵快速幂
- poj 3744 Scout YYF I(概率dp+矩阵快速幂)
- POJ 3744 Scout YYF I 概率dp+矩阵快速幂
- POJ 3744 Scout YYF I 概率dp 矩阵快速幂
- POJ 3744 Scout YYF I (概率DP+矩阵快速幂)
- Spring入门
- ug nx8.0免费版下载 含64位/32位
- hive索引简单使用介绍
- jQuery的环境搭建
- windows远程服务器 上部署javaweb项目
- 【状压dp && 矩阵快速幂】 POJ
- Codeforces 851A && Round #432 Div. 2 A. Arpa and a research in Mexic
- Elasticsearch Java API 的使用(8)—Scroll (游标)API详解
- UNIX环境编程学习笔记(22)——进程管理之system 函数执行命令行字符串
- Excel操作笔记--联动下拉菜单
- Elasticsearch Java API 的使用(9)—Bulk大数据量的批量上传
- ugnx8.5正式版软件 含32位和64位
- 修改mysql字符集冲突
- Vector clock