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,可参考陈丹琦的<基于连通性状态压缩的动态规划问题> ...
随机推荐
- Linux下配置文件的位置
系统级的配置存放在 /etc 目录中.用户级的配置存放在用户的主目录 /home/user_login_name. SHELL 默认文件 /etc/bashrc – bash shell 的系统级默认 ...
- Spring(3.2.3) - Beans(10): 生命周期
Spring 容器可以管理 singleton 作用域 Bean 的生命周期,容器能够跟踪 Bean 实例的创建.销毁.管理 Bean 生命周期行为主要有两个时机: 注入 Bean 的依赖关系之后 即 ...
- 【转载】LinkedIn是如何优化Kafka的
http://www.wtoutiao.com/p/18d5RY0.html 在LinkedIn的数据基础设施中,Kafka是核心支柱之一.来自LinkedIn的工程师曾经就Kafka写过一系列的专题 ...
- RESTful 服务架构风格 * .NET的RESTful框架 OpenRasta
REST 的约束采用的就是掌控 Web 的基本原则.这些原则是: 用户代理与资源交互,任何可命名和表达的事物都可称为资源.每项资源都有一个唯一的统一资源标识符 (URI). 与资源的交互(通过其唯一的 ...
- 淘淘实惠多www.taohuiduo.com-专注独家折扣、1折特卖、9块9包邮、全场包邮
淘淘实惠多-http://www.taohuiduo.com 专注独家折扣.1折特卖.9块9包邮.品牌折扣.20元封顶.全场包邮,所有的促销商品包括男装.女装.箱包配饰.母婴.日用.化妆品.数码.男鞋 ...
- Android布局属性全面剖析
第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layout_centerVertical 垂直居中 android:la ...
- Viewpager+Fragment出现空白页面的问题
写了三个Fragment,一次点击跳转显示正常,如果从第一个直接跳转到第三个,第三个页面会出现空白界面. 问题找到了:原来动态获取数据页面数据不显示,页面显示空白,就是onCreateView每次都调 ...
- DB2存储过程实现查询表数据,生成动态SQL,并执行
一.动态执行SQL PREPARE S1 FROM 'delete from test'; EXECUTE S1; 二.使用游标 DECLARE V_CURSOR CURSOR FOR SELECT ...
- javascript 基础API
Math.random() 取值范围[0,1) 大于等于0小于1,包括0,不包括1 Math.floor() 向下取整 Math.ceil() 向上取整 第一题:一组数的规则如下:1.1.2.3. ...
- [Guava学习笔记]Collections: 不可变集合, 新集合类型
我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3843386.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...