题意:
从n个数中选若干个数,使它们的异或和最大。n<=100
Solution
经典的异或高斯消元。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
//O(60*n) #include <iostream> using namespace std; int n; long long a[109]; int main() { ios::sync_with_stdio(); cin >> n; long long ans = 0; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 62; i >= 0; --i) { for (int j = 1; j <= n; ++j) { if (a[j] & 1LL << i ) { long long t = a[j]; if (! (ans & 1LL << i ) ) ans ^= t; for (int k = j; k <= n; ++k) { if (a[k] & 1LL << i ) a[k] ^= t; } } } } cout << ans << endl; return 0; }