HDU 6185 Covering
矩阵快速幂。
一开始的思路是$dfs$出一个矩阵,$k[i][j]$表示这一行是状态$i$,将这一行填满,下一行是$j$状态的方案数。然后就可以矩阵快速幂了,但是矩阵大小是$16*16$的,超时了......
仔细观察后会发现,第$0$行状态为$0$,因此往后填充的过程中,并不会出现16种情况,只会在6种状态之间转移:$0000$,$1111$,$1100$,$0011$,$0110$,$1001$。那么只要构造$6*6$的矩阵就可以了。
#include<bits/stdc++.h>
using namespace std; const int mod = 1e9 + 7;
int k[6][6];
long long n;
map<long long ,int> ans;
struct M {
int r;
int c;
int a[6][6];
}; M mul(const M &a, const M &b) {
M res;
res.r = a.r;
res.c = b.c;
memset(res.a, 0, sizeof res.a);
for(int j = 0; j < res.c; j ++) {
for(int k = 0; k < a.c ; k ++) {
if(b.a[k][j] == 0) continue;
for(int i = 0; i < res.r; i ++) {
long long u = (long long)a.a[i][k] * (long long)b.a[k][j] % (long long)mod;
res.a[i][j] = (res.a[i][j] + (int)u) % mod;
}
}
}
return res;
} void init() {
memset(k, 0, sizeof k);
/*
0 | 0000
1 | 1111
2 | 1100
3 | 0011
4 | 0110
5 | 1001
*/
k[0][0] ++;
k[0][1] ++;
k[0][2] ++;
k[0][3] ++;
k[0][5] ++; k[1][0] ++; k[2][0] ++;
k[2][3] ++; k[3][0] ++;
k[3][2] ++; k[4][5] ++; k[5][4] ++;
k[5][0] ++;
} void work(long long p) {
M a;
memset(a.a, 0, sizeof a.a);
a.r = 6;
a.c = 6;
for(int i = 0; i < 6; i ++) {
a.a[i][i] = 1;
} M b;
b.r = 6;
b.c = 6;
for(int i = 0; i < 6; i ++) {
for(int j = 0; j < 6; j ++) {
b.a[i][j] = k[i][j];
}
} M c;
memset(c.a, 0, sizeof c.a);
c.r = 1;
c.c = 6;
c.a[0][0] = 1; while(p) {
if(p & 1) {
p --;
a = mul(a, b);
}
p = p >> 1;
b = mul(b, b);
} c = mul(c, a);
ans[p] = c.a[0][0];
printf("%d\n", c.a[0][0]);
} int main() {
init();
while(~scanf("%lld", &n)) {
work(n);
}
return 0;
}
HDU 6185 Covering的更多相关文章
- HDU 6185 Covering 矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6185 题意:用 1 * 2 的小长方形完全覆盖 4 * n的矩形有多少方案. 解法:小范围是一个经典题 ...
- HDU - 6185 Covering(暴搜+递推+矩阵快速幂)
Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...
- HDU - 6185 :Covering(矩阵乘法&状态压缩)
Bob's school has a big playground, boys and girls always play games here after school. To protect bo ...
- hdu 6185 递推+【矩阵快速幂】
<题目链接> <转载于 >>> > 题目大意: 让你用1*2规格的地毯去铺4*n规格的地面,告诉你n,问有多少种不同的方案使得地面恰好被铺满且地毯不重叠.答案 ...
- HDU 6185(打表代码
/** @xigua */ #include <cstdio> #include <cmath> #include <iostream> #include < ...
- hdu 6185 递推+矩阵快速幂
思路:考虑全部铺满时,前2列的放法.有如下5种情况:(转自http://blog.csdn.net/elbadaernu/article/details/77825979 写的很详细 膜一下) 假设 ...
- HDU 2295 Radar (重复覆盖)
Radar Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- POJ 3831 & HDU 3264 Open-air shopping malls(几何)
题目链接: POJ:id=3831" target="_blank">http://poj.org/problem?id=3831 HDU:http://acm.h ...
- HDU 1565:方格取数(1)(最大点权独立集)***
http://acm.hdu.edu.cn/showproblem.php?pid=1565 题意:中文. 思路:一个棋盘,要使得相邻的点不能同时选,问最大和是多少,这个问题就是最大点权独立集. 可以 ...
随机推荐
- bootstrap 栅格calss
container container-fluid row col-xs- col-sm- col-md- col-lg- col-md-offset- col-md-push- col-md-pul ...
- [DeeplearningAI笔记]序列模型1.7-1.9RNN对新序列采样/GRU门控循环神经网络
5.1循环序列模型 觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.7对新序列采样 基于词汇进行采样模型 在训练完一个模型之后你想要知道模型学到了什么,一种非正式的方法就是进行一次新序列采 ...
- OpenCV---像素运算
像素运算 分为算术运算和逻辑运算 算术运算: 加减乘除 调节亮度 调整对比度 逻辑运算: 与或非 遮罩层控制 一:算术运算 import cv2 as cv import numpy as np de ...
- 使用 JSONDoc 记录 Spring Boot RESTful API
这个博文可以分为两部分:第一部分我将编写一个Spring Boot RESTful API,第二部分将介绍如何使用JSONDoc来记录创建的API.做这两个部分最多需要15分钟,因为使用Spring ...
- C11线程管理:原子变量&单调函数
1.原子变量 C++11提供了原子类型std::atomic<T>,可以使用任意类型作为模板参数,使用原子变量就不需要使用互斥量来保护该变量,用起来更加简洁. 举个例子,如果要做一个计数器 ...
- Lua的各种资源2
Lua Directory This page is a top level directory of all Lua content at this wiki, grouped by top ...
- [php]禁用缓存
header("Expires: -1"); header("Cache-Control: no_cache"); header("pragma: n ...
- 【CodeForces】585 E. Present for Vitalik the Philatelist
[题目]E. Present for Vitalik the Philatelist [题意]给定n个数字,定义一种合法方案为选择一个数字Aa,选择另外一些数字Abi,令g=gcd(Ab1...Abx ...
- oracle imp dmp命令
vi par.txt userid=system/oracle tables=(user.table,...) query="where org_no like 32%" file ...
- python设计模式之单例模式(一)
前言 单例模式是创建模式中比较常见和常用的模式,在程序执行的整个生命周期只存在一个实例对象. 系列文章 python设计模式之单例模式(一) python设计模式之常用创建模式总结(二) python ...