# BZOJ 2844: albus就是要第一个出场

## 2844: albus就是要第一个出场

Time Limit: 6 Sec  Memory Limit: 128 MB
Submit: 1134  Solved: 481
[Submit][Status][Discuss]

3
1 2 3
1

## Sample Output

3

N = 3, A = [1 2 3]
S = {1, 2, 3}
2^S = {空, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}
f(空) = 0
f({1}) = 1
f({2}) = 2
f({3}) = 3
f({1, 2}) = 1 xor 2 = 3
f({1, 3}) = 1 xor 3 = 2
f({2, 3}) = 2 xor 3 = 1
f({1, 2, 3}) = 0

B = [0, 0, 1, 1, 2, 2, 3, 3]

## HINT

1 <= N <= 10,0000

## Source

[Submit][Status][Discuss]

N个数的线性基如果只有M个，即原本N个数的组合方案为$2^{N}个$，而线性基的组合方案仅仅为$2^{M}$个，那么每个线性基的子集异或和用N个数有$2^{N-M}$个组合方案。

 1 #include <cstdio>
2
3 __inline void swap(int &a, int &b)
4 {
5     a^= b ^= a ^= b;
6 }
7
8 const int mod = 10086;
9 const int mxn = 100005;
10
11 int n, m, a[mxn], b[mxn], c, ans = 1;
12
13 inline int pow(int a, int b)
14 {
15     int ret = 1;
16
17     for (; b; b >>= 1, (a *= a) %= mod)
18         if (b & 1)(ret *= a) %= mod;
19
20     return ret;
21 }
22
23 inline void gauss(void)
24 {
25     for (int i = 1; i <= n; ++i)
26     {
27         for (int j = i + 1; j <= n; ++j)
28             if (a[i] < a[j])swap(a[i], a[j]);
29
30         if (a[i])
31             ++c;
32         else
33             break;
34
35         for (int j = 31; j >= 0; --j)
36             if ((a[i] >> j) & 1)
37             {
38                 b[i] = j;
39
40                 for (int k = 1; k <= n; ++k)
41                     if (k != i && (a[k] >> j) & 1)
42                         a[k] ^= a[i];
43
44                 break;
45             }
46     }
47 }
48
49 signed main(void)
50 {
51     scanf("%d", &n);
52
53     for (int i = 1; i <= n; ++i)
54         scanf("%d", a + i);
55
56     gauss();
57
58     scanf("%d", &m);
59
60     for (int i = 1; i <= c; ++i)
61         if ((m >> b[i]) & 1)m ^= a[i],
62             (ans += pow(2, n - i)) %= mod;
63
64     printf("%d\n", ans);
65 }

@Author: YouSiki

posted @ 2017-02-01 11:19  YouSiki  阅读(115)  评论(0编辑  收藏  举报