Bzoj 1299 [LLH Invitational] chocolate bar game (nim game) + construction __sg

Source: Internet
Author: User
link : Method: Game + construction parsing: the question did not think how to do, after reading Wyf uncle said to understand The question is to have n heaps of stones, and then you have two ways to do it every time. The first is a NIM game on an established NIM game. The second option is to select several heaps in the unassigned heap to join this NIM game. So how does this work. I've been trying to build a losing streak, but maybe I've gone too far thinking about turning this problem into Nim's Nim game and eventually going into a dead end. However, the inevitable failure of this problem can be built in this way: if it is the first step, I can create a 0 Nim game, at this time the latter has two ways, the second is in the Nim game, then the play can be the game of different or and into 0, The second is to choose a new Pebble heap to join the original NIM game, and if it is a play, it will not give the next chance to add a set of different or 0 of the gravel heap. So the first step to build must be the choice of the most elements of the different or and for the 0 Nim game, at this time, in the remaining heap, must not have a set of gravel heap of different or and 0, which is obvious. so if the latter chooses the second approach, it will make the original NIM game different or and not 0, so the first step can be the game's differences or and into 0. that is, if the first pick starts with the most gravel heap to create a different or and 0 Nim game, then the latter will fail. It can also be transformed, if the tempo can be chosen for an arbitrary number of gravel set up by the different or and 0 Nim game, then the latter will fail. it's obvious. The range of the gravel heap is 14, so we can 214 2^{14} direct Dfs gan. or Gauss elimination. But obviously the former is 2333. Code:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N
using namespace std;
int n;
int a[n];
BOOL V[n];
int flag;
void Dfs (int no)
{
    if (no==n+1)
    {
        int ans=0,cnt=0;
        for (int i=1;i<=n;i++) if (v[i]) ans^=a[i],cnt++;
        if (!ans&&cnt!=0)
        {
            flag=1;
        }
        return;
    } 
    V[no]=1;dfs (no+1);
    V[no]=0;dfs (no+1);
}
int main ()
{
    int tot=10;
    while (tot--)
    {
        scanf ("%d", &n);
        for (int i=1;i<=n;i++) scanf ("%d", &a[i]);
        memset (v,0,sizeof (v));
        flag=0;
        DFS (1);
        if (flag) puts ("NO");
        Else puts ("YES");
    }

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.