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. html5 之 canvas 相关知识(一)概念及定义

    什么是 Canvas? HTML5 的 canvas 元素使用 JavaScript 在网页上绘制图像. 画布是一个矩形区域,您可以控制其每一像素. canvas 拥有多种绘制路径.矩形.圆形.字符以 ...

  2. 面试之BI-SQL--table转换[2]

    month   salesPerMonth 1 2 2 3 3 2 4 4 5 3 6 3                                 写条SQL语句把上表转成下表: month  ...

  3. Ajax-数据格式-xml,json

    xml demo testDataXml <%@ page language="java" contentType="text/html; charset=UTF- ...

  4. Kill Session

    有时候创建索引或修改表字段时,会提示资源正忙,可以查出表对应的进程并kill掉 select l.session_id,o.owner,o.object_name from v$locked_obje ...

  5. Cocos2d-x实例:设置背景音乐与音效- AppDelegate实现

    为了进一步了解背景音乐和音效播放的,我们通过一个实例给大家介绍一下.如下图所示有两个场景:HelloWorld和Setting.在HelloWorld场景点击“游戏设置”菜单可以切换到Setting场 ...

  6. 【C语言】01-第一个c程序代码分析

    创建了一个C程序,接下来分析一下里面的代码. 项目结构如下: 一.代码分析 打开项目中的main.c文件(C程序的源文件拓展名为.c),可以发现它是第一个C程序中的唯一一个源文件,代码如下: 1 #i ...

  7. System.Windows.Forms.Timer

    一.主要属性.方法和事件 Windows 窗体 Timer 是定期引发事件的组件.该组件是为 Windows 窗体环境设计的. 时间间隔的长度由 Interval 属性定义,其值以毫秒为单位.若启用了 ...

  8. ZigBee HomeAutomation分析

    引用请注明出处!联系邮箱是huhao0126@163.com 本例程讲解,基于TI CC2530-2.5.1a中的HomeAutomation文件夹中的SampleLight和SampleSwitch ...

  9. Windows系统 环境变量

    用户变量与系统变量 用户变量只对当前用户有效,而系统变量对所有用户有效.在检索命令时,系统变量会排在用户变量的前面.也就是说,如果两个地方都包含同一个命令,则优先执行系统变量指示路径下的命令. set ...

  10. java学习笔记_GUI(5)

    demo如何为不同的button创建对应的响应函数 import javax.swing.*; import java.awt.event.*; import java.awt.*; class My ...