HDU1760 A New Tetris Game NP State

Source: Internet
Author: User

A New Tetris Game

Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1457 Accepted Submission (s): 713

problem DescriptionOnce, Lele and his sister favorite, play the longest game is the Tetris (Tetris).
Gradually, Lele found that playing this game only requires deft on hand, almost without thinking through the brain.
So, Lele came up with a new play.

Lele and sister first took out a rectangular chessboard, the chessboard some of the grid is not available, the rest is usable. Lele and elder sister take out Tetris Square square box (size is 2*2 square square box), take turns to put in the chessboard, notice is, put in the square block can not be stacked on the board is not available on the grid, also can not be stacked on the square square that already put.
In the end, no one can put the square box, who loses.

Now, assuming every time Lele and sister are very smart, can be the best strategy to put a square, and each time is lele first put a square, can you tell him whether he will win sister? InputThis topic contains multiple sets of tests, please handle to the end of the file.
The first row of each group of tests contains two positive integers N and M (0<N*M<50) representing the number of rows and columns of the chessboard, respectively.
Next there are n rows, each with a number of M 0 or 1 representing the entire board.
where 0 is representative of the chessboard that location is available, and 1 is the chessboard that is not available for the location

You can assume that there are no more than 40 0 in each board. OutputFor each set of tests, if Lele is sure to win, output "Yes" in one line, otherwise output "No".   Sample Input4 400000000000000004 40000001001000000 Sample OutputYesNo

Test instructions: give you a n*m rectangle, 0 means empty, 1 Conversely, now two people take turns to put 2*2 rectangle, who can not put, who will lose.

The NP state of each State is determined by the successor State, in which the P-states are both N states and the subsequent States are all n-states, both P-states

The status of the subsequent state is the same as that of recursive violence can be calculated

#include <bits/stdc++.h>#defineMes (x) memset (x, 0, sizeof (x));#definell __int64Const Long LongMoD = 1e9+7;Const intMAX =0x7ffffff;using namespacestd;intN,m, a[ -][ -];//NP StateintDfs () { for(intI=1; i<n;i++)         for(intj=1; j<m;j++)            if(a[i][j]==0&&a[i-1][j-1]==0&&a[i-1][j]==0&&a[i][j-1]==0) {A[i][j]= a[i-1][j-1] = a[i][j-1] = a[i-1][J] =1; if(DFS () = =0) {A[i][j]= a[i-1][j-1] = a[i][j-1] = a[i-1][J] =0; return 1; } A[i][j]= a[i-1][j-1] = a[i][j-1] = a[i-1][J] =0; }    return 0;}intMain () { while(~SCANF ("%d%d", &n, &m)) {         for(intI=0; i<n;i++)             for(intj=0; j<m;j++) scanf ("%1d", &A[i][j]); printf ("%s\n", DFS ()?"Yes":"No"); }    return 0;}

HDU1760 A New Tetris Game NP State

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.