博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU1693 Eat The Trees(插头dp)
阅读量:7126 次
发布时间:2019-06-28

本文共 2543 字,大约阅读时间需要 8 分钟。

 

Eat the Trees

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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 2
63 – 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.
 

 

Source
 
最简单的插头dp,代码风格来自baidu...
自己一定要画图模拟。。
然后一定要看论文而不是ppt
Codes:
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 using namespace std; 9 #define For(i,n) for(int i=1;i<=n;i++)10 #define Rep(i,l,r) for(int i=l;i<=r;i++)11 12 int T,n,m,G[13][13];13 long long dp[13][13][1<<13];14 15 void DP(){16 dp[0][m][0] = 1;17 For(i,n){18 Rep(j,0,1<

 

转载于:https://www.cnblogs.com/zjdx1998/p/3904145.html

你可能感兴趣的文章
MySQL按照月进行统计
查看>>
解决python语言在cmd下中文乱码的问题
查看>>
如何遍历Set对象
查看>>
iOS之CALayer属性简介
查看>>
ucos 统计任务 OS_TaskStat()
查看>>
I.MX6 U-boot imxotp MAC address 写入
查看>>
Error: No EPCS layout data - looking for section [EPCS-C84018]
查看>>
使用sql对数据库进行操作
查看>>
java 继承内存分配
查看>>
三级菜单
查看>>
【python3的学习之路十二】面向对象高级编程
查看>>
Kali渗透测试——EtherApe
查看>>
Hibernate执行流程
查看>>
@Value注入static属性
查看>>
java使用jdbi连接几种数据库的方法
查看>>
Mac OS下 selenium 驱动safari日志
查看>>
向一个数组中添加100个不重复的随机数的几个方法
查看>>
用java解压缩zip和rar的工具类
查看>>
restful开发API
查看>>
停止表单submit提交
查看>>