# bzoj 3105

 1 /**************************************************************
2     Problem: 3105
3     User: idy002
4     Language: C++
5     Result: Accepted
6     Time:8 ms
7     Memory:1272 kb
8 ****************************************************************/
9
10 #include <cstdio>
11 #include <iostream>
12 #include <algorithm>
13 #define N 110
14 using namespace std;
15
16 typedef long long dnt;
17
18 int n;
19 int aa[N], bb[N];
20 int stk[N], top;
21 dnt ans;
22
23 bool ok() {
24     for( int t=0; t<top; t++ )
25         bb[t] = stk[t];
26     for( int b=30,j=0; b>=0 && j<top; b-- ) {
27         for( int k=j; k<top; k++ ) {
28             if( (bb[k]>>b) & 1 ) {
29                 swap(bb[k],bb[j]);
30                 break;
31             }
32         }
33         if( (bb[j]>>b) & 1 ) {
34             for( int k=j+1; k<top; k++ )
35                 if( (bb[k]>>b) & 1 ) {
36                     bb[k] ^= bb[j];
37                     if( bb[k]==0 ) return false;
38                 }
39             j++;
40         }
41     }
42     return true;
43 }
44 int main() {
45     scanf( "%d", &n );
46     for( int i=0; i<n; i++ )
47         scanf( "%d", aa+i );
48     sort( aa, aa+n, greater<int>() );
49     dnt ans = 0;
50     for( int i=0; i<n; i++ ) {
51         stk[top++] = aa[i];
52         if( !ok() ) {
53             top--;
54             ans += aa[i];
55         }
56     }
57     printf( "%lld\n", ans );
58 }
59 
View Code

posted @ 2015-05-22 21:49  idy002  阅读(198)  评论(0编辑  收藏  举报