ZOj 3466 The Hive II
There is a hive in the village. Like this. There are 8 columns(from A to H) in this hive. Different colums have the same number of grids. Every grid has its own coordinate, which is formed by two uppercases, representing the row index and the column index. The row index starts from A. And the hive has less than ten rows in total. The following figure shows a hive with two rows.

There is honey in some grids. A naughty bee discovers this special hive and hopes to eat all honey in the hive. However, this strange bee sets some rules for itself while eating. They are descirbed as following:
- It must eat the honey by choosing a circuit and then eat all honey that is in the chosen circuit.
- Honey will disappear immediately after the bee eats it.
- All grids which are in the circuit should has honey in it.
- The length of the circuit should be no less than 3.
- The bee can choose more than one circuit to eat honey.
Given the hive and the honey in it, how many different ways can this naughty bee eat all honey in the hive?
Input
There are multiple test cases.
For each case, there are two integers N(0 < N ≤ 10) and M(0 ≤ M ≤ N * 8) in the first line. N represents the size of the hive, which means there are N rows in the hive in total. All grids have honey in it except for those M grids listed in the following line. Each empty grid is described by its coordinate(using two uppercases).
Output
For each case, output the number of different ways the bee can eat all honey in the hive. It's guaranteed that the answer does not exceed 263 - 1.
Sample Input
3 5
BB CD BF AH CG
Sample Output
3
Hint
The following figure shows all different ways for the sample. The black grids represent those which are initially empty.

六边形插头DP诶,好像很兹磁的样子……
码起来其实也不会太麻烦。轮廓线放在列上而不要放在行上会好写很多(其实就是把地图旋转90°),只是可能稍慢。二进制记录有无插头,然后对于一个点的三个入插头就分0,1,2个的情况算,哪一个或者哪两个都是没关系的,3个显然不合法。
然后……只记得我错把n打成m,然后调了很久(我说怎么8 0的时候答案正确,9 0就挂了……)
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define MMH(a,b,c) up(no.x,gx(2*x,a,b,c,no.z),an)
using namespace std;
const int MAXN=;
struct na{
int x,z;
na(int xx,int zz):x(xx),z(zz){}
};
int n,m=,M,x,y,z,a[],k,en,ln;
bool Q[][];
ll f[][MAXN+],mmh;
int v[][MAXN+];
queue <na> q;
inline int gx(int x,int q1,int q2,int q3,int k){q1^=;q2^=;q3^=;k|=(<<x)|(<<(x+))|(<<(x+));k^=(q1<<x)|(q2<<(x+))|(q3<<(x+));return k;}
inline void up(int x,int z,ll lj){
k=(++x)&;
if (v[k][z]!=x) v[k][z]=x,f[k][z]=,q.push(na(x,z));
f[k][z]=f[k][z]+lj;
}
char c[];
int main(){
register int i,j;
while(~scanf("%d%d",&n,&M)){
mmh=;
memset(Q,,sizeof(Q));
memset(v,,sizeof(v));
for (i=;i<n;i++)
for (j=;j<m;j++) Q[i][j]=;
for (i=;i<M;i++)
scanf("%s",&c),Q[n-(c[]-'A')-][c[]-'A']=;
en=n*m;
while(!Q[en%n][en/n]&&en>) en--;en++;
f[][]=v[][]=;
q.push(na(,));
while(!q.empty()){
na no=q.front();q.pop();
ll an=f[no.x&][no.z];
if (ln!=no.x) ln=no.x,y=ln/n,x=ln-y*n;
if (x==&&(y&)==) no.z<<=;
for (i=,j=no.z;j;i++,j>>=) a[i]=j%;
for (;i<=(n<<);i++) a[i]=;
if (!Q[x][y]){
if (no.x==en) mmh+=an;else
MMH(,,);
}else
if (y&){
if (a[*x]+a[*x+]+a[*x+]==){
if (Q[x][y+]&Q[x+][y+]) MMH(,,);
if (Q[x][y+]&Q[x+][y]) MMH(,,);
if (Q[x+][y+]&Q[x+][y]) MMH(,,);
}else if (a[*x]+a[*x+]+a[*x+]==){
if (Q[x][y+]) MMH(,,);
if (Q[x+][y+]) MMH(,,);
if (Q[x+][y]) MMH(,,);
}else if (!(a[*x]&a[*x+]&a[*x+])) MMH(,,);
}else{
if (a[*x]+a[*x+]+a[*x+]==){
if (x) if (Q[x-][y+]&Q[x][y+]) MMH(,,);
if (x) if (Q[x-][y+]&Q[x+][y]) MMH(,,);
if (Q[x][y+]&Q[x+][y]) MMH(,,);
}else if (a[*x]+a[*x+]+a[*x+]==){
if (x) if (Q[x-][y+]) MMH(,,);
if (Q[x][y+]) MMH(,,);
if (Q[x+][y]) MMH(,,);
}else if (!(a[*x]&a[*x+]&a[*x+])) MMH(,,);
}
}
printf("%llu\n",mmh);
}
}
1490MS 52920KB
ZOj 3466 The Hive II的更多相关文章
- ZOJ 3466 The Hive II (插头DP,变形)
题意:有一个n*8的蜂房(6边形的格子),其中部分是障碍格子,其他是有蜂蜜的格子,每次必须走1个圈取走其中的蜂蜜,在每个格子只走1次,且所有蜂蜜必须取走,有多少种取法? 思路: 以前涉及的只是n*m的 ...
- zoj 3620 Escape Time II dfs
题目链接: 题目 Escape Time II Time Limit: 20 Sec Memory Limit: 256 MB 问题描述 There is a fire in LTR ' s home ...
- hive(II)--sql考查的高频问题
在了解别人hive能力水平的时候,不管是别人问我还是我了解别人,有一些都是必然会问的东西.问的问题也大都大同小异.这里总结一下我遇到的那些hive方面面试可能涉及的问题 1.行转列(列转行) 当我们建 ...
- zoj 3356 Football Gambling II【枚举+精度问题】
题目: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3356 http://acm.hust.edu.cn/vjudge/ ...
- zoj 3620 Escape Time II
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4744 Escape Time II Time Limit: 2 Seconds ...
- ZOJ 3332 Strange Country II
Strange Country II Time Limit: 1 Second Memory Limit: 32768 KB Special Judge You want to v ...
- ZOJ 3042 City Selection II 【序】【离散化】【数学】
题意: 输入数据n,m.n代表工厂的数量,m代表城市的数量. 接下来n+m行为工厂和城市的坐标. 规定如图所示方向刮风,工厂的air会污染风向地区的air. 注意,工厂和城市的坐标表示的是从x到x+1 ...
- zoj 3627 Treasure Hunt II (贪心)
本文出自 http://blog.csdn.net/shuangde800 题目链接:zoj-3627 题意 直线上有n个城市, 第i个城市和i+1个城市是相邻的. 每个城市都有vi的金币. ...
- ZOJ3466-The Hive II
题意 有一个六边形格子,共 \(n\) 行,每行有 8 个位置,有一些格子不能走.求用一些环覆盖所有可走格子的方案数.\(n\le 10\) . 分析 插头dp,只不过是六边形上的,分奇数列和偶数列讨 ...
随机推荐
- OC学习14——谓词
一.谓词的基本概念与使用 1.谓词(NSPredicate)用于定义一个逻辑条件,通过该条件可执行搜索或内存中的过滤操作.上一篇文章中介绍的集合都提供了使用谓词对集合进行过滤的方法.OC中的谓词操作是 ...
- ios 去掉字符串中的空格 和指定的字符
[问题分析] .使用NSString中的stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]方法只是去掉左右 ...
- NOIP2017day1游记
NOIP 2017总结 Day1 Day1T1 第一眼看到瞬间慌掉,woc这玩意啥! 然后懵逼了两分钟 好的 我相信他是NOIP第一题 那我就打个表吧 然后花五分钟打了个暴力 玩了几组数据 哇!好像有 ...
- 用LinkedList集合演示栈和队列的操作
在数据结构中,栈和队列是两种重要的线性数据结构.它们的主要不同在于:栈中存储的元素,是先进后出:队列中存储的元素是先进先出.我们接下来通过LinkedList集合来演示栈和队列的操作. import ...
- 基于Vue的SPA动态修改页面title的方法
最近基于VUE做个SPA手机端web发现动态修改页面标题通过document.title=xxxx 来修改着实蛋疼,而且在IOS的微信端据说没效果.百度发现要针对IOS的微信做点额外的操作,即:创建一 ...
- 安装MongoDB步骤
1.第一步是从官网下载匹配自己操作系统的安装文件或压缩文件: 2.随便找个文件夹先解压安装文件,然后在C盘根目录建立一个新文件夹命名为mongodb: 3.将打开刚刚安装的文件,将bin文件夹拷贝到C ...
- 1.Nginx服务应用
Nginx服务应用 Nginx的优点和作用 Nginx是一款高性能的HTTP和反向代理的服务器软件,还是一个IMAP/POP3/SMTP(邮件)代理服务器! Nginx在功能实现上都采用模块化结构设计 ...
- Nodejs的运行原理-架构篇
前言 本来是想只做一个Nodejs运行原理-科普篇,但是收到了不少私信,要我多分享一些更进阶,更详细的内容,所以我会在接下来的两个月里继续更新Nodejs运行原理. PS:此系列只做Nodejs的运行 ...
- 微信小程序红包开发 小程序发红包 开发过程中遇到的坑 微信小程序红包接口的
最近公司在开发一个小程序红包系统,客户抢到红包需要提现.也就是通过小程序来给用户发红包. 小程序如何来发红包呢?于是我想到两个方法. 之前公众号开发一直用了的.一个是红包接口,一个是企业支付接口.一开 ...
- Ruby学习之元编程
Kernel#evel()方法 和Object#instance_evel().Module#class_evel()方法类似,evel()方法也是一个内核方法,Object#instance_eve ...