Problem Description
Most of us know that in the game called DotA(Defense of the Ancient), Pudge is a strong hero in the first period of the game. When the game goes to end however, Pudge is not a strong hero any more.
So Pudge’s teammates give him a new assignment—Eat the Trees!

The trees are in a rectangle N * M cells in size and each of the cells either has exactly one tree or has nothing at all. And what Pudge needs to do is to eat all trees that are in the cells.
There are several rules Pudge must follow:
I. Pudge must eat the trees by choosing a circuit and he then will eat all trees that are in the chosen circuit.
II. The cell that does not contain a tree is unreachable, e.g. each of the cells that is through the circuit which Pudge chooses must contain a tree and when the circuit is chosen, the trees which are in the cells on the circuit will disappear.
III. Pudge may choose one or more circuits to eat the trees.

Now Pudge has a question, how many ways are there to eat the trees?
At the picture below three samples are given for N = 6 and M = 3(gray square means no trees in the cell, and the bold black line means the chosen circuit(s))

Input
The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases.
For each case, the first line contains the integer numbers N and M, 1<=N, M<=11. Each of the next N lines contains M numbers (either 0 or 1) separated by a space. Number 0 means a cell which has no trees and number 1 means a cell that has exactly one tree.

Output
For each case, you should print the desired number of ways in one line. It is guaranteed, that it does not exceed 263 – 1. Use the format in the sample.

Sample Input
2
6 3
1 1 1
1 0 1
1 1 1
1 1 1
1 0 1
1 1 1
2 4
1 1 1 1
1 1 1 1

Sample Output
Case 1: There are 3 ways to eat the trees.
Case 2: There are 2 ways to eat the trees.

最简单的插头dp

题目大意

给出一个M*N的地图,部分格子是障碍。
现把所有非障碍格子连起来,要求每个格子有且仅有有两个相邻格子与之相连,
问有多少种方案。
(N,M<=11)

插头dp的两个重要元素就是插头和决策线(这个还是去看论文吧)

主要就是讨论换行的情况和不换行的情况

然后就是讨论那个凸角的情况,还有当前决策的格子是不是障碍物,仔细一点就没问题了

被hdu坑了,pascal不能用<<,忘记用int64结果WA了,还好测了一下大数据发现了

 var
f:array[..,..,..]of int64;
a:array[..,..]of longint;
n,m,time,t:longint; procedure init;
var
i,j:longint;
begin
fillchar(f,sizeof(f),);
fillchar(a,sizeof(a),);
read(n,m);
for i:= to n do
for j:= to m do
read(a[i,j]);
f[,m,]:=;
end; procedure work;
var
i,j,k:longint;
begin
for i:= to n do
for j:= to m do
if j= then
begin
if a[i,j]= then
for k:= to shl m- do
if k and = then inc(f[i,j,k shl +],f[i-,m,k])
else
begin
inc(f[i,j,k shl ],f[i-,m,k]);
inc(f[i,j,k shl -],f[i-,m,k]);
end
else
for k:= to shl m- do
if k and = then inc(f[i,j,k shl ],f[i-,m,k]);
end
else
begin
if a[i,j]= then
for k:= to shl (m+)- do
if k and( shl (j-))> then
if k and( shl j)> then inc(f[i,j,k- shl (j-)],f[i,j-,k])
else
begin
inc(f[i,j,k],f[i,j-,k]);
inc(f[i,j,k+ shl (j-)],f[i,j-,k]);
end
else
if k and( shl j)> then
begin
inc(f[i,j,k],f[i,j-,k]);
inc(f[i,j,k- shl (j-)],f[i,j-,k]);
end
else inc(f[i,j,k+ shl (j-)],f[i,j-,k])
else
for k:= to shl (m+)- do
if k and( shl (j-))= then inc(f[i,j,k],f[i,j-,k]);
end;
writeln('Case ',time,': There are ',f[n,m,],' ways to eat the trees.');
end; begin
read(t);
for time:= to t do
begin
init;
work;
end;
end.

Eat the Trees hdu 1693的更多相关文章

  1. 【HDU】1693 Eat the Trees

    http://acm.hdu.edu.cn/showproblem.php?pid=1693 题意:n×m的棋盘求简单回路(可以多条)覆盖整个棋盘的方案,障碍格不许摆放.(n,m<=11) #i ...

  2. hdu 1693 Eat the Trees——插头DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1693 第一道插头 DP ! 直接用二进制数表示状态即可. #include<cstdio> # ...

  3. HDU 1693 Eat the Trees(插头DP、棋盘哈密顿回路数)+ URAL 1519 Formula 1(插头DP、棋盘哈密顿单回路数)

    插头DP基础题的样子...输入N,M<=11,以及N*M的01矩阵,0(1)表示有(无)障碍物.输出哈密顿回路(可以多回路)方案数... 看了个ppt,画了下图...感觉还是挺有效的... 参考 ...

  4. HDU 1693 Eat the Trees(插头DP)

    题目链接 USACO 第6章,第一题是一个插头DP,无奈啊.从头看起,看了好久的陈丹琦的论文,表示木看懂... 大体知道思路之后,还是无法实现代码.. 此题是插头DP最最简单的一个,在一个n*m的棋盘 ...

  5. HDU 1693 Eat the Trees

    第一道(可能也是最后一道)插头dp.... 总算是领略了它的魅力... #include<iostream> #include<cstdio> #include<cstr ...

  6. HDU - 1693 Eat the Trees(多回路插头DP)

    题目大意:要求你将全部非障碍格子都走一遍,形成回路(能够多回路),问有多少种方法 解题思路: 參考基于连通性状态压缩的动态规划问题 - 陈丹琦 下面为代码 #include<cstdio> ...

  7. 【HDU】1693:Eat the Trees【插头DP】

    Eat the Trees Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  8. HDU 1693 Eat the Trees(插头DP,入门题)

    Problem Description Most of us know that in the game called DotA(Defense of the Ancient), Pudge is a ...

  9. Eat the Trees(hdu 1693)

    题意:在n*m的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少中方法. 第一道真正意义上的插头DP,可参考陈丹琦的<基于连通性状态压缩的动态规划问题> ...

随机推荐

  1. jBPM - jBPM Installer

    Prerequisites This script assumes you have Java JDK 1.6+ (set as JAVA_HOME), and Ant 1.7+ installed. ...

  2. hive,spark的远程调试设置

    spark的远程调试 spark-env.sh文件里面,加上下面配置即可: if [ "$DEBUG_MODE" = "true" ]; then export ...

  3. 诡异的问题“该字符串未被识别为有效的 DateTime”

    问题描述:"该字符串未被识别为有效的 DateTime"这个异常相信大家都会碰到,但是这一次真的无法理解,服务器运行一段时间之后才会出现这个问题,并且是系统中所有和日期相关的模块, ...

  4. JavaScript之表格修改

    讲到表格,我们不免都了解它的属性及用途. colspan跨列(纵向的)和rowspan跨行(横向的). 表格中<tr></tr>标签标示行标签:<td></t ...

  5. (转)Hprose与WCF在云计算平台Azure上的对决

    Windows Azure Platform是一个运行在微软数据中心的云计算平台.它包括一个云计算操作系统和一个为开发者提供的服务集合.开发人员创建的应用既可以直接在该平台 中运行,也可以使用该云计算 ...

  6. (转)实战Memcached缓存系统(5)Memcached的CAS程序实例

    1. 非CAS 首先看一个不是CAS的Memcached程序实例.实例的问题原型,见上一篇博文. 程序实例: package com.sinosuperman.memcached; import ja ...

  7. 引用类型之Array类型

    Array类型 ECMAScript数组与其它语言数组一样,都是数据的有序列表.但是ECMAScript数组的每一项可以保存任何类型的数据.而且,ECMAScript数组是可以动态调整的. 1.创建和 ...

  8. 高性能CSS(二)

    避免CSS表达式 CSS表达式是动态设置CSS属性的强大(但危险)方法.Internet Explorer从第5个版本开始支持CSS表达式.下面的例子中,使用CSS表达式可以实现隔一个小时切换一次背景 ...

  9. Js跳出循环

    break和 continue break 中断整个循环 continue 跳出当前循环,进入下一次循环 break示例: 例1: 例2: Continue:跳出当前循环,进入下一次循环 Break与 ...

  10. 跨域访问JSONP CORS

    一.JSONP 常用的Jquery框架支持jsonp方式请求,该方式只支持GET方法,传参大小有限,而且需要后台根据jsonp的请求方式进行封装结果返回. 其中参数jsonp默认为callback,j ...