Bzoj 3105 Cqoi 2013 New Nim Games __ Game theory

Source: Internet
Author: User

The

First gives a conclusion: if there are n piles of matches, each match has A1, A2, a3...an matches, under the rule of the traditional Nim game, if A1^a2^a3^...^an=0 will lose. And these two conclusions are completely equivalent, that is to say, if you do not meet this condition, you will win.
then in the subject, after picking up some matches, if the remaining matches have a subset of the match or 0, then the next hand to remove the other matches, leaving a different or a 0 of the state, so the tempo will fail.
So in order to prevent this, you can't have a subset that makes a subset different or 0, and you can do it with a linear base.
I don't know what the hell is a bunch of puzzle-writing on the web. I guess the feeling of greed + linear base is right ...

 #include <cmath> #include <cstdio> #include <vector> #include <queue > #include <cstring> #include <iomanip> #include <stdlib.h> #include <iostream> #include < Algorithm> #define LL long #define INF 1000000000 #define MOD 1000000007 #define N 10000 #define FO (i,a,b) for (i=a
i<=b;i++) #define FD (I,A,B) for (i=a;i>=b;i--) using namespace std;
int n,i,j;
ll Sum,res;
int a[n],b[n],f[n];
    int main () {scanf ("%d", &n);
    Fo (i,1,n) scanf ("%d", &a[i]);
    Sort (a+1,a+n+1);
    FO (i,1,n) sum + = A[i], b[i] = a[i]; FD (i,n,1) {FD (j,29,0) if (A[i] >> j) & 1 if (!F[J) {F[j] = i; break;}
            else A[i] ^= A[f[j]];
        if (A[i]) res = = B[i]; if (res) printf ("%lld\n", sum-res);
    else printf (" -1\n");
return 0; }

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.