Little H and Little Z are playing a stone game. The rule of stone game is this, each person can take a few stones from a heap, each time the number of stones to be limited, who can not take Stones will lose the game. Small h first to operate, he wants to ask you if he has a winning strategy, if so, the first step how to take the stone.
N≤10 ai≤1000
Bare SG function AH
However, I do not even ask the SG function, WA a while later, according to other code changes to find the Vis common ...
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespaceStd;typedefLong Longll;Const intn= the, m=1005; inlineintRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;} intN,a[n],m,b[n];intSg[m],vis[m];intDfsintu) {//printf ("Dfs%d\n", u); if(sg[u]!=-1)returnSg[u];//printf ("y\n"); BOOLVis[n];memset (Vis,0,sizeof(VIS)); for(intI=1; i<=m && b[i]<=u;i++) Vis[dfs (U-b[i])]=1; for(intI=0;; i++)if(!vis[i]) {sg[u]=i; Break;} returnsg[u];}intMain () {//freopen ("in", "R", stdin);memset (sg,-1,sizeof(SG)); sg[0]=0; N=read (); for(intI=1; i<=n;i++) a[i]=read (); M=read (); for(intI=1; i<=m;i++) b[i]=read (); Sort (b+1, B +1+m); intsum=0; for(intI=1; i<=n;i++) sum^=DFS (A[i]); if(sum!=0) {puts ("YES"); intflag=0; for(intI=1; I<=n &&!flag;i++) for(intj=1; J<=m && b[j]<=a[i];j++) if((Sum^dfs (A[i]) ^dfs (a[i]-b[j]) = =0) {printf ("%d%d\n", I,b[j]); flag=1; Break;} }ElsePuts"NO");}
Bzoj 1874: [BeiJing2009 Wintercamp] Take a stone game [NIM Games sg function]