hdu 1693 Eat the Trees

网友投稿 611 2022-08-29

hdu 1693 Eat the Trees

hdu 1693 Eat the Trees

​​ 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.

Source 2008 “Sunline Cup” National Invitational Contest

Recommend wangye | We have carefully selected several similar problems for you: 1691 1689 1692 1690 1697 插头dp入门 因为这个不要求 仅仅是一个联通块所以考虑设dp[i][j][s]表示 当前在第i,j个格子然后 扫描线的状态是s情况下 方案数量是多少 逐格递推 多画一画就可以知道这个状态是怎么递推的 为了递推方便 设定dp[0][m][0]=1这样在每行交替的时候自动可以更新 因为我们考虑 最后一个右插头和 第二行的第一个右插头是不会存在的 所以需要右移一位

#include#include#include#include#define ll long longusing namespace std;inline char gc(){ static char now[1<<16],*S,*T; if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;} return *S++;}inline int read(){ int x=0,f=1;char ch=gc(); while(!isdigit(ch)) {if (ch=='-') f=-1;ch=gc();} while(isdigit(ch)) x=x*10+ch-'0',ch=gc(); return x*f;}const int N=12;int T,n,m,mp[N][N];ll dp[N][N][1<>j-1)&1,up=(s>>j)&1;int s1=(1<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:PHP获取指定分钟数的下一个整数倍
下一篇:codeforces 992 C Nastya and a Wardrobe
相关文章

 发表评论

暂时没有评论,来抢沙发吧~