51Nod-1033-骨牌覆盖 V2
来源:互联网 发布:软件测试英文简历 编辑:程序博客网 时间:2024/05/19 12:16
ACM模版
描述
题解
第一次接触插头
找了半天找到一个不错的题解,讲得虽然不算十分详细,但是如果看了上述的
代码
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;typedef long long ll;const int mod = 1e9 + 7;const int MAXN = 1 << 5;ll dp[MAXN][MAXN];ll ret[MAXN][MAXN];ll tmp[MAXN][MAXN];int m, n;void dfs(int col, int pre, int now){ if (col > n) { return ; } if (col == n) { dp[pre][now]++; return ; } dfs(col + 1, pre << 1, (now << 1) | 1); dfs(col + 1, (pre << 1) | 1, now << 1); dfs(col + 2, pre << 2 , now << 2);}void mul(ll ret[][MAXN], ll a[][MAXN], ll b[][MAXN]){ int t = 1 << n; for (int i = 0; i < t; i++) { for (int j = 0; j < t; j++) { ll tmp = 0; for (int k = 0; k < t; k++) { tmp += a[i][k] * b[k][j]; tmp %= mod; } ret[i][j] = tmp; } }}int main(){ scanf("%d%d", &m, &n); dfs(0, 0, 0); int t = 1 << n; for (int i = 0; i < t; i++) { ret[i][i] = 1; } m++; while (m) { for (int i = 0; i < t; i++) { for (int j = 0; j < t; j++) { tmp[i][j] = ret[i][j]; } } if (m & 1) { mul(ret, tmp, dp); } m = m >> 1; mul(tmp, dp, dp); for (int i = 0; i < t; i++) { for (int j = 0; j < t; j++) { dp[i][j] = tmp[i][j]; } } } cout << ret[0][t - 1] << endl; return 0;}
阅读全文
0 0
- 51nod 1033 骨牌覆盖v2
- 51nod 1033骨牌覆盖 V2
- 51Nod-1033-骨牌覆盖 V2
- 51nod 1033 骨牌覆盖 V2(矩阵快速幂)
- 51Nod-1032-骨牌覆盖 V2
- 51NOD 1031 骨牌覆盖
- 51nod 1031 骨牌覆盖
- 51nod 1031 骨牌覆盖
- 51nod-1031 骨牌覆盖
- 51nod 1031 骨牌覆盖
- 51nod-【1031 骨牌覆盖】
- 51Nod 1031 骨牌覆盖
- 51Nod 1031 骨牌覆盖
- 51nod 1031骨牌覆盖
- 51nod 1031 骨牌覆盖
- 51nod 1031 骨牌覆盖
- 51nod 1031 骨牌覆盖
- 51Nod 1031 骨牌覆盖
- Linux云服务器安装tomcat
- 美团秋招笔试题--可乐瓶盖
- tensorflow实现Linear Regression
- hbase简介
- Eclipse 的单步调试
- 51Nod-1033-骨牌覆盖 V2
- C++ 享元模式 (纯代码,看原理绕行)
- Spark学习笔记(9)源码解读之Receiver在Driver的精妙实现
- 利用oracle自带工具sql developer导出数据库中的表
- mybatis练习过程中发现需要注意的几点
- HttpServletrequest 与HttpServletResponse总结
- 人性的弱点读书笔记
- python安装gyroid模块
- 最快最简单的排序—桶排序