HDOJ 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

 

Sample Output

题目大意

有一个N*M的棋盘,其中有一些格子是无效的,请问用闭合回路填满整个棋盘有效格子的方案数。

题解

插头DP
定义F[i][j][nowState]表示第i格第j列,当前插头状态为nowState的方案数
因为我们基于联通性DP,所以很显然我们只需要知道轮廓线上的联通情况(就是已DP区域和未DP区域的情况),其实只需要知道M个竖向插头和一个横向插头是否存在的情况。
然后我们根据,已有的插头情况向后一个递推合理的状态。
最后答案就是F[n][m][0]

代码