275. To xor or not to xor

 
The sequence of non-negative integers A1, A2, ..., AN is given. You are to find some subsequence Ai 1, Ai 2, ..., Ai k (1 <= i 1 < i 2 < ... < i k<= N) such, that Ai 1 XOR Ai 2 XOR ... XOR Ai k has a maximum value.
Input
The first line of the input file contains the integer number N (1 <= N <= 100). The second line contains the sequence A1, A2, ..., AN (0 <= Ai <= 10^18). 
Output
Write to the output file a single integer number -- the maximum possible value of Ai 1 XOR Ai 2 XOR ... XOR Ai k
Sample test(s)
Input
 
 

11 9 5 
 
 
Output
 
 
14 
 题意:
  从N个数中选择任意个数,求异或的最大值
题解:
  从高位贪心
  高斯消元判断能否构成1
  复杂度 60*N*N

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18;
const double Pi = acos(-1.0);
const int N = 1e3+, M = 1e6, mod = 1e9+, inf = 2e9; int n,a[][N];
int main() {
scanf("%d",&n);
for(int i = ; i < n; ++i) {
LL x;int cnt = ;
scanf("%I64d",&x);
while(x) {
a[cnt++][i] = x%;
x/=;
}
} for(int i = ; i < ; ++i) a[i][n] = ;
LL ans = ;
for(int i = ; i >= ; --i) {
int x = -;
for(int j = ; j < n; ++j) {
if(a[i][j]) {
x = j;break;
}
}
if(x == - && a[i][n] == ) {
ans += 1LL<<i;
} else if(x != -) {
ans += 1LL<<i;
for(int k = i - ; k >=; --k) {
if(a[k][x]) {
for(int j = ; j <= n; ++j) a[k][j] ^= a[i][j];
}
}
}
}
cout<<ans<<endl;
return ;
}
 

SGU 275 To xor or not to xor 高斯消元求N个数中选择任意数XORmax的更多相关文章

  1. SGU 200. Cracking RSA (高斯消元求自由变元个数)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=200 200. Cracking RSA time limit per test: ...

  2. 【bzoj2115】[Wc2011] Xor DFS树+高斯消元求线性基

    题目描述 输入 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ,Di,表示 Si 与Ti之间存在 一条权值为 Di的无向边. 图 ...

  3. 【HDU 3949】 XOR (线性基,高斯消元)

    XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. [HNOI2011]XOR和路径 概率期望 高斯消元

    题面 题解:因为异或不太好处理,,,因此按位来算,这样最后的答案就是每一位上的值乘对应的权值再求和.本着期望要倒退的原则,,,我们设$f[i]$表示从$i$到$n$,xor和为1的概率.那么观察$xo ...

  5. 【BZOJ2337】[HNOI2011]XOR和路径 期望DP+高斯消元

    [BZOJ2337][HNOI2011]XOR和路径 Description 题解:异或的期望不好搞?我们考虑按位拆分一下. 我们设f[i]表示到达i后,还要走过的路径在当前位上的异或值得期望是多少( ...

  6. 【BZOJ2115】[Wc2011] Xor 高斯消元求线性基+DFS

    [BZOJ2115][Wc2011] Xor Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ...

  7. 【bzoj4269】再见Xor 高斯消元求线性基

    题目描述 给定N个数,你可以在这些数中任意选一些数出来,每个数可以选任意多次,试求出你能选出的数的异或和的最大值和严格次大值. 输入 第一行一个正整数N. 接下来一行N个非负整数. 输出 一行,包含两 ...

  8. HDU3949/AcWing210 XOR (高斯消元求线性基)

    求第k小的异或和,用高斯消元求更简单一些. 1 //用高斯消元求线性基 2 #include<bits/stdc++.h> 3 using namespace std; 4 #define ...

  9. ACM学习历程—SGU 275 To xor or not to xor(xor高斯消元)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=275 这是一道xor高斯消元. 题目大意是给了n个数,然后任取几个数,让他们xor和 ...

随机推荐

  1. One Edit Distance

    Given two strings S and T, determine if they are both one edit distance apart. 分析:https://segmentfau ...

  2. POJ 1062 ( dijkstra )

    http://poj.org/problem?id=1062 一个中文题,一个多月之前我做过,当时我是用搜索写的,不过苦于卡在无法确定等级关系,所以就错了. 看了别人的博客后,我还是不是很理解所谓的枚 ...

  3. mysql开启binlog

    mysql开启binlog,至于为什么要开启binlog,可以google下. ## 设置server_id,一般设置为IP server_id= ## 复制过滤:需要备份的数据库名,多个库以逗号分隔 ...

  4. Qt 常用的功能

    1.程序重启 void Widget::reStart() {   qApp->closeAllWindows(); QProcess::startDetached(qApp->appli ...

  5. Spring+SpringMVC+Mybatis 多数据源整合(转)

    转载自:http://blog.csdn.net/q908555281/article/details/50316137 目录(?)[-]拷贝所需jar拷贝jar文件需要的jar文件入下图所示因为我的 ...

  6. 【python】入门学习(七)

    设置字符串格式: format % values >>> x =/ >>> print(x) 0.012345679012345678 >>> p ...

  7. 【python】为什么修改全局的dict变量不用global关键字

    转自:http://my.oschina.net/leejun2005/blog/145911?fromerr=qnPCgI19#OSC_h4_8 为什么修改字典d的值不用global关键字先声明呢? ...

  8. MyBatis之CRUD

    1 mybatis框架介绍 1.1回顾jdbc操作数据库的过程 1.2 mybatis开发步骤 A.提供一个SqlMapperConfig.xml(src目录下),该文件主要配置数据库连接,事务,二级 ...

  9. C#资源文件管理

    1.右键项目点属性; 2.点资源项,添加资源下拉框的添加现在文件,如下图: 3.直接上代码获取并复制到指定文件夹下: private void button1_Click(object sender, ...

  10. Spring 注释 @Autowired 和@Resource

    一. @Autowired和@Resource都可以用来装配bean,都可以写在字段上,或者方法上. 二. @Autowired属于Spring的:@Resource为JSR-250标准的注释,属于J ...