zoj 3466(插头DP 多条回路 六边形)

16 篇文章 0 订阅

 

The Hive II
Time Limit: 5 Seconds       Memory Limit: 65536 KB

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.

Photo

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.

Photo

 

Author: MO, Luyi
Contest: ZOJ Monthly, January 2011

分析:此题为连通性dp(插头DP),可以横着dp,也可以竖着dp,竖着来会超时,因为n<=10>8。。。不管怎样,状态转移都差不多,用二进制表示每个插头的状态,如图

黑色箭头表示所有的插头,每一行转移都先转移在上面的BDFH,即偶数列,每一格控制三个插头的状态,用8进制表示,插头的状态由上面三个黑色转移到下面三个红色,ACEG的转移类似。。。

把状态的连接保存在数组中,转移时直接枚举然后用位移计算相应的位置,并计算状态。。。

(000)<->(101,110,011)   (100,010,001)<->(100,010,001) 这些状态互相转化。。。

代码(写得好挫,不过还是可以AC的):

 

竖着来写比较简单,方法类似横着,不过因为这题数据原因,只能超时了。。。‍:

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值