HDU 5724 Chess Game

Source: Internet
Author: User

Topic links

An n-row 20-column checkerboard. Each line has a number of pieces. Two people in turn, each time a piece can be moved to the right one position, if it has a piece to the right, skip this piece, if there are a number of pieces, will be the number of skipped. But the pieces cannot move out of the boundary.

If there is no way to move, even if you lose. Ask you to go first can win.

Only 20 columns, so the SG value of all states is preprocessed. And then the direct different or just fine.

Then sg[(1<<20)-1] = 0, which is required to lose the state, the other can be DFS out, the specific look at the code.

#include <bits/stdc++.h>using namespacestd;#definePB (x) push_back (x)#definell Long Long#defineMK (x, y) make_pair (x, y)#defineLson L, M, rt<<1#defineMem (a) memset (a, 0, sizeof (a))#defineRson m+1, R, rt<<11#defineMem1 (a) memset (a,-1, sizeof (a))#defineMEM2 (a) memset (a, 0x3f, sizeof (a))#defineRep (i, N, a) for (int i = A; i<n; i++)#defineFi first#defineSe Secondtypedef pair<int,int>PLL;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-8;Const intMoD = 1e9+7;Const intINF =1061109567;Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} };intsg[1<< A];intMexintx) {    if(~Sg[x])returnx; BOOLvis[ -]; memset (Vis,false,sizeof(VIS));  for(inti =0; I < -; i++) {        if(((1<<i) &x) = =0&& (1<< (i+1)) &x)) {intJ;  for(j = i +2; J < -; J + +) {                if(! (1<<j&x)) Break; }             for(intK = i+1; K <= J; k++) {                intSTA = x^ (1<<i) ^ (1<<k); if(Sta>= (1<< -))                     Break;                MEX (STA); Vis[sg[sta]]=1; }        }    }     for(inti =0; I < -; i++)        if(!Vis[i])returnSG[X] =i;}voidinit () {MEM1 (SG); sg[(1<< -)-1] =0;  for(inti =0; I < (1<< -); i++) {        if(Sg[i] = =-1) {mex (i); }    }}intMain () {init (); intt, N, M, X; CIN>>T;  while(t--) {cin>>N; intAns =0;  for(inti =0; I < n; i++) {scanf ("%d", &m); intSTA =0;  while(m--) {scanf ("%d", &x); STA|= (1<< ( --x)); } ans^=Sg[sta]; }        if(ans) {puts ("YES"); } Else{puts ("NO"); }    }}

HDU 5724 Chess Game

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.