Hdu 1760 A New Tetris Game Game ~ ~ Search for SG function

Source: Internet
Author: User

A New Tetris GameTime limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1176 Accepted Submission (s): 557


Problem description once, 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?

Input This 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.
Output for each set of tests, if the Lele has the certainty to win, in a row of "Yes", or Output "No".

Sample Input
4 400000000000000004 40000001001000000

Sample Output
YesNo
A very good question, combined with the search. We know through the definition of the SG function that when a point can go to a losing point, this is the win point. When a point can go to the point is to win the point. That must be the point of defeat ~ ~ Code:
#include <stdio.h> #include <string.h> #define MAX 55bool Map[max][max]; int N, m;bool judge (int i, int j) {if (i +1<n && j+1<m) {if (Map[i][j] && map[i+1][j] && map[i][j+1] && map[i+1][j+1]) { return true;}} return false;} BOOL DFS () {for (int i = 0, i < n; ++i) {for (int j = 0; j < m; ++j) {if (judge (I,j)) {Map[i][j] = map[i+1][j] = Map[i] [j+1] = map[i+1][j+1] = false; DFS ()) {map[i][j] = map[i+1][j] = map[i][j+1] = map[i+1][j+1] = true; return true;} MAP[I][J] = map[i+1][j] = map[i][j+1] = map[i+1][j+1] = true;}}} return false;}  int main () {while (~scanf ("%d%d", &n,&m)) {char-line[100]; for (int i = 0; i < n; ++i) {scanf ("%s", line); for (Int J = 0; J < M; ++J) {if (line[j] = = ' 0 ') map[i][j] = true; Elsemap[i][j] = false;}} if (DFS ()) puts ("Yes"), Elseputs ("No")  ;} return 0;

with June

Hdu 1760 A New Tetris Game Game ~ ~ Search for SG function

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.