Bzoj 3105: [cqoi2013] New NIM game

Source: Internet
Author: User

Title: http://www.lydsy.com/JudgeOnline/problem.php?id=3105

Test instructions is to take some number so that the remaining number of XOR and the subset is not 0

Quasi-array. Solve maximal linear independent groups. Greedy from large to small put, open 31 vectors to indicate the number of binary I-digit case, if a number can be represented by the previous number, then this number is not taken. Note Long long.

#include <cstring>#include<iostream>#include<algorithm>#include<cstdio>#defineMAXN 109#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#definell Long Longusing namespacestd;intn,m= to; ll ANS,SUM,A[MAXN],W[MAXN],BIN[MAXN];intRead () {intx=0, f=1;CharCh=GetChar ();  while(!isdigit (CH)) {        if(ch=='-') f=-1; Ch=GetChar (); }     while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar (); }    returnx*F;}BOOLcmpintXinty) {    returnX>y;}intMain () {n=read (); Rep (I,1, n) a[i]=read (), sum+=A[i]; Rep (I,1, m) bin[i]=1<< (I-1); Sort (a+1, A +1+n,cmp); Rep (I,1, N) {        intnow=A[i]; Down (j,m,1)if(a[i]&Bin[j]) {            if(W[j]) a[i]^=A[w[j]]; Else{W[j]=i;  Break; }        }        if(A[i]) ans+=Now ; }    if(ans!=0) printf ("%lld\n", sum-ans); ElsePuts"-1"); return 0;}

Bzoj 3105: [cqoi2013] New NIM game

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.