SGU 275 To xor or not to xor(高斯消元)
2015-05-17 19:10
423 查看
题意:
从n个数中选若干个数,使它们的异或和最大。n<=100
Solution
经典的异或高斯消元。
O(63*n)
从n个数中选若干个数,使它们的异或和最大。n<=100
Solution
经典的异或高斯消元。
//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; }
O(63*n)
相关文章推荐
- ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)
- SGU 275 To xor or not to xor【最大xor和 高斯消元】
- SGU 275 To xor or not to xor (高斯消元)
- SGU 275 To xor or not to xor (贪心+高斯消元)
- SGU 275 To xor or not to xor (高斯消元)
- sgu 275 To xor or not to xor(高斯消元判断是否有解)
- SGU 275 To xor or not to xor (高斯消元)
- SGU 275 To xor or not to xor 高斯消元求N个数中选择任意数XORmax
- SGU-275 To xor or not to xor 高斯消元
- SGU 275 - To xor or not to xor 按位贪心 线性基
- 【高斯消元】[SGU275]To xor or not to xor
- SGU 275 - To xor or not to xor 按位贪心 线性基
- SGU 275 - To xor or not to xor 按位贪心 线性基
- SGU 275 - To xor or not to xor 按位贪心 + XOR性质
- SGU 275 - To xor or not to xor 按位贪心 线性基
- SGU 275 - To xor or not to xor 按位贪心 线性基
- To xor or not to xor 高斯消元求异或
- SGU 275 - To xor or not to xor 按位贪心 线性基
- SGU 275 - To xor or not to xor 按位贪心 线性基
- SGU 275 - To xor or not to xor 按位贪心 线性基