"HDU 1693" Eat the Trees

Source: Internet
Author: User

Eat the TreesTime limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3004 Accepted Submission (s): 1448


Problem Descriptionmost of us know that in the game called DotA (Defense of the Ancient), Pudge are a strong hero in the FIR St 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 is in a rectangle N * M cells in size and each of the cells either have exactly one tree or have nothing at all. And what Pudge needs-to-eat all trees, that's in the cells.
There is several rules Pudge must follow:
I. Pudge must eat the trees by choosing a circuit and he then would eat all trees that is in the chosen circuit.
II. The cell that does not contain a tree was unreachable, e.g. each of the cells is through the circuit which Pudge C Hooses must contain a tree and when the circuit was chosen, the trees which is in the cells on the circuit would disappear.
Iii. Pudge Choose one or more circuits to eat the trees.

Now Pudge have a question, how many ways is there to eat the trees?
At the below three samples is given for N = 6 and M = 3 (gray square means no trees in the cell, and the bold Blac K Line means the chosen circuit (s))



Inputthe input consists of several test cases. The first line of the input is the number of the cases. There is no more than cases.
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 have no trees and number 1 means a cell that have exactly one tree.

Outputfor the should print the desired number of ways in one line. It is guaranteed, the it does not exceed 263–1. Use the format in the sample.
Sample Input
26 31 1 11 0 11 1 11 1 11 0 11 1 12 41 1 1 11 1 1 1

Sample Output
Case 1:there is 3 ways to eat the trees. Case 2:there is 2 ways to eat the trees.

Source2008 "Sunline Cup" National Invitational Contest
Recommendwangye

Plug DP entry question.


The simplest plug DP problem (in fact, the idea of the topic is a simplified plug DP idea, not widely applicable to plug DP)


Here's the puzzle.


The transfer between rows and rows is ______| transfer to |______, the horizontal line is the same, then directly to the left of the previous line is the first one of the line.


 #include <iostream> #include <cstring> #include <cstdio> #include < Algorithm> #include <cmath>using namespace std;int n,m,a[20][20];long long f[20][20][1<<15];void PLUGDP () {f[0][m][0]=1;for (int i=1;i<=n;i++) {for (int j=0;j< (1<<m); j + +) F[i][0][j<<1]=f[i-1][m][j];for ( int j=1;j<=m;j++) for (int k=0;k< (1<< (m+1)), k++) {int y=1<<j,x=1<< (j-1), if (A[i][j]) {if (k &y) && (k&x)) F[i][j][k]=f[i][j-1][k-x-y];else if (! ( K&X) &&! (K&y)) F[i][j][k]=f[i][j-1][k+x+y];else f[i][j][k]=f[i][j-1][k^x^y]+f[i][j-1][k];} Else{if (! ( K&X) &&! (K&y)) F[i][j][k]=f[i][j-1][k];else f[i][j][k]=0;}}} printf ("There is%lld ways to eat the trees.\n", F[n][m][0]);}    int main () {int T; scanf ("%d", &t), for (int i=1;i<=t;i++) {scanf ("%d%d", &n,&m), and for (Int. i=1;i<=n;i++) for (int j=1;j< =m;j++) scanf ("%d", &a[i][j]);p rintf ("Case%d:", i); PLUGDP ();} return 0;} 


"HDU 1693" Eat the Trees

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.