The 2018 ACM-ICPC Asia Qingdao Regional Contest, Online

K XOR Clique

BaoBao has a sequence a​1​​,a​2​​,...,a​n​​. He would like to find a subset S of {1,2,...,n} such that ∀i,j∈S, a​i​​⊕a​j​​<min(a​i​​,a​j​​) and ∣S∣ is maximum, where ⊕ means bitwise exclusive or.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1≤n≤10​5​​), indicating the length of the sequence.

The second line contains n integers: a​1​​,a​2​​,...,a​n​​ (1≤a​i​​≤10​9​​), indicating the sequence.

It is guaranteed that the sum of n in all cases does not exceed 10​5​​.

Output

For each test case, output an integer denoting the maximum size of S.

Sample Input

3
3
1 2 3
3
1 1 1
5
1 2323 534 534 5

Sample Output

2
3
2
#include"bits/stdc++.h"
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
const int maxn = 1e5+5;
int a[maxn];
int max1=-1;
 int bitcount(int x)
 {
 	int res=0;
     while(x!=0)
	 {
	 	x>>=1;
	 	res++;
		 }    
		 return res;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		max1=-1;
		rep(i,0,n-1)
		{
			cin>>a[i];
			a[i]=bitcount(a[i]);
		}
		sort(a,a+n);
		int ans=0,flag;
		rep(i,0,n-2)
		{
			ans=0;
			flag=0;
			while(a[i]==a[i+1])
			{
				ans++;
				i++;
				flag=1;
		    }
		    if(flag)
			i--;
			if(max1<=ans)
			max1=ans;
		}
		cout<<max1+1<<endl;
	}
	return 0;
 } 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值