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,只不过是六边形上的,分奇数列和偶数列讨 ...
随机推荐
- rsync 指定端口拷贝
rsync -aP -e 'ssh -p 2288' ssh-audit.dat 172.18.18.31:/opt/freesvr/audit/sshgw-audit/sbin
- DNS查询相关
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/45 一种简单的设计方式是在因特网上使用一个DNS服务器,该服务器 ...
- lesson - 12 课程笔记
一.w 命令 作用: 用于显示已经登录系统的用户列表, 并显示用户正在执行的指令. 执行这个命令可得知目前登入系统的用户有哪些人, 以及他们正在执行的程序. 单独执行w 命令会显示所有的用户, 您也 ...
- Linux(CentOS6.5)下编译安装Nginx1.10.1
首先在特权账号(root)下安装编译时依赖项: yum install gcc gcc-c++ perl -y 首先以非特权账号(本文以账号comex为例)登陆OS: 进入data目录下载相关安装 ...
- Qt数据库集成应用封装
平时的大大小小的项目中,基本上都需要与数据库打交道,会遇到各种各样的应用场景,本人主要遇到四种场景1:数据库自动重连,例如mysql数据库中经常遇到服务器挂掉的情况,需要自动检测并重新连接数据库.2: ...
- Git_学习_03_ ignore文件配置
一.示例 # 1.Compiled class file *.class bin target # 2.Log file *.log logs # 3. Package Files # *.war * ...
- ExpandableListView的完美实现,JSON数据源,右边自定义图片
转载请标明出处: http://www.cnblogs.com/dingxiansen/p/8194669.html 本文出自:丁先森-博客园 最近在项目中要使用ExpandableListView来 ...
- python爬虫爬取大众点评并导入redis
直接上代码,导入redis的中文编码没有解决,日后解决了会第一时间上代码!新手上路,多多包涵! # -*- coding: utf-8 -*- import re import requests fr ...
- idea为tomcat设置虚拟地址
1.设置tomcat的server.xml <Host name="localhost" appBase="webapps" unpackWARs=&qu ...
- 理解JavaScript原型
Javascript原型总会给人产生一些困惑,无论是经验丰富的专家,还是作者自己也时常表现出对这个概念某些有限的理解,我认为这样的困惑在我们一开始接触原型时就已经产生了,它们常常和new.constr ...