Eat the Trees hdu 1693
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的更多相关文章
- 【HDU】1693 Eat the Trees
http://acm.hdu.edu.cn/showproblem.php?pid=1693 题意:n×m的棋盘求简单回路(可以多条)覆盖整个棋盘的方案,障碍格不许摆放.(n,m<=11) #i ...
- hdu 1693 Eat the Trees——插头DP
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1693 第一道插头 DP ! 直接用二进制数表示状态即可. #include<cstdio> # ...
- HDU 1693 Eat the Trees(插头DP、棋盘哈密顿回路数)+ URAL 1519 Formula 1(插头DP、棋盘哈密顿单回路数)
插头DP基础题的样子...输入N,M<=11,以及N*M的01矩阵,0(1)表示有(无)障碍物.输出哈密顿回路(可以多回路)方案数... 看了个ppt,画了下图...感觉还是挺有效的... 参考 ...
- HDU 1693 Eat the Trees(插头DP)
题目链接 USACO 第6章,第一题是一个插头DP,无奈啊.从头看起,看了好久的陈丹琦的论文,表示木看懂... 大体知道思路之后,还是无法实现代码.. 此题是插头DP最最简单的一个,在一个n*m的棋盘 ...
- HDU 1693 Eat the Trees
第一道(可能也是最后一道)插头dp.... 总算是领略了它的魅力... #include<iostream> #include<cstdio> #include<cstr ...
- HDU - 1693 Eat the Trees(多回路插头DP)
题目大意:要求你将全部非障碍格子都走一遍,形成回路(能够多回路),问有多少种方法 解题思路: 參考基于连通性状态压缩的动态规划问题 - 陈丹琦 下面为代码 #include<cstdio> ...
- 【HDU】1693:Eat the Trees【插头DP】
Eat the Trees Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 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 ...
- Eat the Trees(hdu 1693)
题意:在n*m的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少中方法. 第一道真正意义上的插头DP,可参考陈丹琦的<基于连通性状态压缩的动态规划问题> ...
随机推荐
- js如何判断一个数组中是否有重复的值
引自:http://bbs.tianya.cn/post-414-38497-1.shtml 方法一: var ary = new Array("111","22&quo ...
- Commons IO - IOUtils
IOUtils is a general IO stream manipulation utilities. This class provides static utility methods fo ...
- Commons JXPath - Modifying Object Graphs
JXPath 除了可以 XPath 语法访问 JavaBeans.DOM/JDOM,也可以对其属性赋值. 以下面的 JavaBeans 为例. package com.huey.jxpath; imp ...
- django 学习-7 模型数据操作
1.首先还是创建办一个项目和一个应用 django.admin.py startproject ssj cd ssj django.admin.py startapp sdj 那 ...
- C#算法基础之递归排序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- ScrollView 与ListView 滑动冲突完美解决
一.介绍ListView高度的设置方法 二.根据实际需求解决冲突问题 一.介绍ListView高度的设置方法 在ScrollView中使用ListView,ListView的高度会不正常. 方式一:在 ...
- hdoj1423 最长上升公共子序列
hdoj1423 题目分析: 两个数组a[n1] , b[n2], 求最长上升公共子序列. 我们可用一维存储 f[i] 表示 b 数组以 j 结尾, 与 a[] 数组构成的最长公共上升子序列. 对数组 ...
- 使用TreeView+ListBox+TxtBox 资料管理器
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- sql中的触发器、视图、事务
·触发器(trigger) [触发器本质上还是一个存储过程,只不过不是用exe来调用执行,而是通过增删改数据库的操作] [触发器只对增.删.改有效] 触发器的格式 (instead of与for的区别 ...
- 20141015--for语句2
for语句,打印等腰三角形: 第一种方法:(使用for语句嵌套) 第二种方法:(定义string型变量) 以下是其他形状的等腰三角形: (穿插使用了for语句嵌套,定义string型)