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,可参考陈丹琦的<基于连通性状态压缩的动态规划问题> ...
随机推荐
- IE9+浏览器input文本框/密码框后面的小叉子/小眼睛清除
为了方便我们的触控操作,IE高等浏览器针对input及input type="password"分别提供了快速清除钮(X图标)以及密码文字显示钮(小眼睛图标)的功能. 由于这经常跟 ...
- Android 异常捕获
在用户使用APP时,如果APP毫无征兆的突然退出程序,又没有任何提示信息.我想这是一种最差劲的用户体验了吧,如果是我估计干脆就直接卸载APP了.因此,作为Android开发者对于这种情况的发生一定要有 ...
- SQL_转换格式的函数—CAST()和CONVERT()
将一种数据类型的表达式显式转换为另一种数据类型的表达式.CAST 和 CONVERT 提供相似的功能. cast SELECT CAST('12.5' AS int) --在将 varchar 值 ' ...
- Jquery插件的编写和使用
第七章 Jquery插件的编写和使用 插件的定义: 插件也称为扩展,是一种遵循一定规范的应用程序接口编写出来的程序. 下面是Jquery插件的编写很使用:要查看请点击:Jquery插件的编写很使 ...
- Visual Assist X 10.6.1837完美破解版(带VS2010破解)
Visual Assist X 10.6.1837完美破解版(带VS2010破解) 实用软件, 资源分享Add comments 八102011 转载自:http://www.blog.namind. ...
- win2003域控制器密码遗忘如何修改
在公司遇到这么个事儿,员工搭建QC服务器,设置了域账户登陆系统.但忘记了登录密码,使用PE直接修改sam文件不好用. 1.使用PE进系统修改组登陆方式的账号administrator密码 需符合复 ...
- 【转】Linux杀死fork产生的子进程的僵尸进程defunct
僵尸进程 就是 已经结束,但是还没有清理出去的.用kill -9 $PID 也无法杀死. 所以程序中应该避免出现僵尸进程. 用fork之后,父进程如果没有wait /waitpid 等待子进程的话,子 ...
- 洛谷 P1508 Likecloud-吃、吃、吃
P1508 Likecloud-吃.吃.吃 题目提供者JosephZheng 标签 动态规划 难度 普及/提高- 题目背景 问世间,青春期为何物? 答曰:"甲亢,甲亢,再甲亢:挨饿,挨饿,再 ...
- linux电源管理系列(一)
本系列将逐步介绍linux电源管理相关的知识,涉及到常见电源管理机制.linux电源管理机制.linux驱动中有关电源管理的相关接口.内核文档中关于Linux电源管理架构文档的分析.以下将以此来介绍相 ...
- C++与Lua交互(三)
通过上一篇的热身,我们对C++调用lua变量有了一个认识,现在让我们再深入一点,去探索一下如何调用lua的函数.表. Lua与宿主通讯的关键--栈 lua是个动态脚本语言,它的数据类型如何映射到C++ ...