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,只不过是六边形上的,分奇数列和偶数列讨 ...
随机推荐
- 小白的Python之路 if __name__ == '__main__' 解析
if __name__ == '__main__' 参考文献: http://www.cnblogs.com/xuxm2007/archive/2010/08/04/1792463.html http ...
- JavaScript基础2——关于变量
变量的声明 变量的定义:使用var关键字来声明,区分大小写的.注意:不用var,会污染全局变量. 变量的命名规范是:字母,数字,$符 ...
- java.lang基础数据类型boolean、char、byte、short、int、long、float、double (JDK1.8)
java.lang.Boolean public static int hashCode(boolean value) { return value ? 1231 : 1237; } JDK 1.8新 ...
- Intellj Idea使用tomcat部署不成功,死活也找不到解决办法的看这里
Intellij 周六晚上开发一个简单web项目的,使用tomcat打包部署,死活也没法部署成功,和这个问题怼了6个小时,也没搞清楚具体为什么不能访问页面,但是好在最后还是找了个方法把问题解决了.以下 ...
- Linux 学习记录 二 (文件的打包压缩).
前言:本文参考<鸟哥的Linux 私房菜>,如有说的不对的地方,还请指正!谢谢! 环境:Centos 6.4 和window不同,在Linux压缩文件需要注意的是,压缩后的文件会 ...
- Udacity并行计算课程笔记-The GPU Programming Model
一.传统的提高计算速度的方法 faster clocks (设置更快的时钟) more work over per clock cycle(每个时钟周期做更多的工作) more processors( ...
- find 命令的误差估值与单位调整
一.命令简介 find 命令的 -size 参数 单位b(不是byte而是block).c.w.k.M.G.默认是单位b ,也就是1block = 512byte = 0.5kb (文件系统ext4) ...
- gitlab 远程 定时备份
=============================================== 2017/11/1_第2次修改 ccb_warlock 更新 ...
- Weblogic用户名密码获取
1.获取服务器上的Weblogic用户名.密码 工具:Xshell 第一步:连接至服务器上,新建目录: mkdir /scripts/DecryptionDemo 第二步:将Decrypt.java放 ...
- base64格式图片转换为FormData对象进行上传
原理:理由ArrayBuffer.Blob和FormData var base64String = /*base64图片串*/; //这里对base64串进行操作,去掉url头,并转换为byte va ...