首页 技术 正文
技术 2022年11月21日
0 收藏 473 点赞 4,565 浏览 1310 个字

You are given an array a1,a2,…,an

of integer numbers.

Your task is to divide the array into the maximum number of segments in such a way that:

  • each element is contained in exactly one segment;
  • each segment contains at least one element;
  • there doesn’t exist a non-empty subset of segments such that bitwise XOR of the numbers from them is equal to 0
  • .

Print the maximum number of segments the array can be divided into. Print -1 if no suitable division exists.

Input

The first line contains a single integer n

(1≤n≤2⋅105

) — the size of the array.

The second line contains n

integers a1,a2,…,an (0≤ai≤109

).

Output

Print the maximum number of segments the array can be divided into while following the given constraints. Print -1 if no suitable division exists.

Examples

Input

4
5 5 7 2

Output

2

Input

3
1 2 3

Output

-1

Input

3
3 1 10

Output

3

题意:给你一些树,让你给树分组,然后把每一个分组看成元素,满足没有元素集合的异或和位0。

思路:首先知道一点,我们得到线性基的时候,当1的个数num(基底个数)不等于元素个数时,表示可以拼凑出0 ;那么,如果全部数的异或为0,那么无解;否则,我们现在得到了线性基,最多划分为几个集合呢,答案就是num。 因为这num个位置的最高位1的位置不同,他们是线性无关的。

(给出N个数,要从中选出一个最大的子集,使得子集中的任意个元素异或值不为0,答案也是基底

#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int p[],ans;
int main()
{
int N,sum=,num=,x;
scanf("%d",&N);
rep(i,,N) {
scanf("%d",&x); sum^=x;
rep2(j,,){
if(x&(1LL<<j)){
if(p[j]) x^=p[j];
else { p[j]=x;break;}
}
}
}
if(sum==) return puts("-1"),;
rep(i,,) if(p[i]){
p[num++]=p[i];
rep(j,i+,) if((p[j]>>i)&) p[j]^=p[i];
}
printf("%d\n",num);
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,020
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,359
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,142
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,772
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,850