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. HDFS原理介绍

    HDFS(Hadoop Distributed File System )Hadoop分布式文件系统.是根据google发表的论文翻版的.论文为GFS(Google File System)Googl ...

  2. LINQ查询字符串判断是否大写

    #region Linq to 字符串char.IsUpper意思是判断是否大写            //string strDemo = "HelloWord!";       ...

  3. poj 2251

    http://poj.org/problem?id=2251 一道简单的BFS,只不过是二维数组,变三维数组,也就在原来基础上加了两个方向. 题意就是从S走到E,#不能走. #include < ...

  4. mysql性能优化学习笔记-参数介绍及优化建议

    MySQL服务器参数介绍 mysql参数介绍(客户端中执行),尽量只修改session级别的参数. 全局参数(新连接的session才会生效,原有已经连接的session不生效) set global ...

  5. ACM/ICPC 之 最短路-Floyd+SPFA(BFS)+DP(ZOJ1232)

    这是一道非常好的题目,融合了很多知识点. ZOJ1232-Adventrue of Super Mario 这一题折磨我挺长时间的,不过最后做出来非常开心啊,哇咔咔咔 题意就不累述了,注释有写,难点在 ...

  6. ffmpeg-20160811-bin.7z

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...

  7. FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM

    FFMpeg ver 20160219-git-98a0053 滤镜中英文对照 2016.02.21 by 1CM T.. = Timeline support 支持时间轴 .S. = Slice t ...

  8. Navicat连接oracle,出现Only compatible with oci version 8.1 and&nb (转)

    与本地oracle连接的时候,一般没问题,sqlplus和oci都是本地oracle自带的,(设置: 工具->选项->oci) 分别为:   oci:D:\app\pcman\produc ...

  9. mysql格式化整数类型时间生成年月日时分秒格式(long或string接收)

    数据库格式: 数据库mysql语句: FROM_UNIXTIME( s.timemodified, '%Y-%m-%d %h:%i:%s' ) 生成结果: 测试sql为: SELECT *, FROM ...

  10. 【XLL API 函数】 xlGetInst

    返回正在调用 DLL 的 Excel 实例的实例句柄. 原型 Excel4(xlGetInst, LPXLOPER pxRes, 0); /* returns low part only */ Exc ...