Bzoj 3105 [cqoi2013] New NIM game plan __ Games

Source: Internet
Author: User
link : Method: Quasi- matrix parsing: we are the upper-tempo operation. so we just need to leave a situation where the situation does not differ or equals zero. each pile of matches is considered a binary number. then we just need to come up with a maximal linearly independent group to achieve the situation we want. so now set m=s,l m={s,l},s is a matrix of all the numbers, L is the maximal linearly independent group we take out. so now if we can testify that this thing is hereditary and also has an exchange, then he is a quasi-array of spicy. In fact, the main is the establishment of the exchange of evidence. then WYF has such a piece of evidence.

Set A,b∈i, and | a|<| B|, we have to prove the existence of x∈b, so that a∪{x}∈i. Using the method of absurdity, it is assumed that for any x∈b-a, a∪{x} does not belong to I, then the elements in the b-a are in the different or space of a, and can be different or represented by a subset of a.
So the elements in B are in the XOR or space of a. Then there must be B's different or space contained in A's different or space. by | a|<| b| and a,b linearly unrelated, obviously contradictory. So the commutative existence is equivalent to any two maximal linearly independent groups of the proof vector group. This is the linear algebra tutorial, go to see the proof. So we have proved the greedy optimality by the pseudo matrix, and then we just need to get greedy to solve a maximal linearly independent group. and then it's like the Gauss elimination. Code:

 #include <cstdio> #include <cstring> #include <iostream> #include <
Algorithm> #define N-using namespace std;
typedef long Long LL;
int a[n];
int b[n];
int n;
ll sum;
ll ans;
    int cmp (int x,int y) {return x>y;} int main () {scanf ("%d", &n);
    for (int i=1;i<=n;i++) scanf ("%d", &a[i]), sum+=a[i];
    Sort (a+1,a+n+1,cmp);
        for (int i=1;i<=n;i++) {int tmp=a[i];
                for (int j=30;j>=0;j--) {if (a[i]& (1<<J)) if (!b[j]) {b[j]=i;break;}
        else A[i]^=a[b[j]];
    } if (a[i]!=0) ans+=tmp;
    } if (ans==0) printf (" -1\n");
else printf ("%lld\n", Sum-ans); }

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.