The problem is the transformation of the Nim game. Every time the pop out of the chocolate is a new NIM, but if the initiator to take a 0 and no matter how to take the rest of the left can not be zero on the line. Then run with Dfs.
The problem is dry:
Descriptiontbl and X play games with chocolate bars. Each time a person can take a number of chocolate bars out of the box, or eat a chocolate bar out of a positive integer length. TBL Two people take turns, unable to operate the loser. They made a total of 10 rounds (one box at a time) with the best strategy. Can you predict the outcome? Input data total 20 rows. 2nd i-1 line A positive integer NI, which represents the number of the first round of chocolate bars. The 2nd i row ni positive integer li,j, indicating the length of the first round chocolate bar. Output data total 10 rows. Each line outputs "YES" or "NO" to indicate whether the TBL will win. Output "NO" if it wins , otherwise output "YES"
Code:
#include <iostream>#include<cstdio>#include<cmath>#include<ctime>#include<queue>#include<algorithm>#include<cstring>using namespacestd;#defineDuke (I,a,n) for (int i = a;i <= n;i++)#defineLV (i,a,n) for (int i = a;i >= n;i--)#defineClean (a) memset (A,0,sizeof (a))Const intINF =1<< -; typedefLong LongLl;typedefDoubledb;template<classT>voidRead (T &x) { CharC; BOOLOP =0; while(c = GetChar (), C <'0'|| C >'9') if(c = ='-') op =1; X= C-'0'; while(c = GetChar (), C >='0'&& C <='9') x= x *Ten+ C-'0'; if(OP) x =-x;} Template<classT>voidwrite (T x) {if(X <0) Putchar ('-'), x =-x; if(x >=Ten) Write (X/Ten); Putchar ('0'+ x%Ten);}intn,sg[2020],a[ .],found;voidDfsintXintUsed,intNow ) { if(x = = n +1) { if(!now && used >0) found =1; return; } DFS (x+1, Used,now); DFS (x+1, used +1, now ^a[x]);}intMain () {intK =Ten; while(k--) {memset (SG,-1,sizeof(SG)); Found=0; Read (n); Duke (I,1, N) read (a[i]); DFS (1,0,0); if(Found = =1) printf ("no\n"); Elseprintf ("yes\n"); } return 0;}
B1299 [LLH Invitational] game Theory of chocolate bar