adly, the problem setter couldn't think of an interesting story, thus he just asks you to solve the following problem.
Given an array a� consisting of n� positive integers, count the number of non-empty subsequences for which the bitwise AND��� of the elements in the subsequence has exactly k� set bits in its binary representation. The answer may be large, so output it modulo 109+7109+7.
Recall that the subsequence of an array a� is a sequence that can be obtained from a� by removing some (possibly, zero) elements. For example, [1,2,3][1,2,3], [3][3], [1,3][1,3] are subsequences of [1,2,3][1,2,3], but [3,2][3,2] and [4,5,6][4,5,6] are not.
Note that AND��� represents the bitwise AND operation.
Input
Each test contains multiple test cases. The first line contains the number of test cases t� (1≤t≤1041≤�≤104). The description of the test cases follows.
The first line of each test case consists of two integers n� and k� (1≤n≤2⋅1051≤�≤2⋅105, 0≤k≤60≤�≤6) — the length of the array and the number of set bits that the bitwise AND��� the counted subsequences should have in their binary representation.
The second line of each test case consists of n� integers ai�� (0≤ai≤630≤��≤63) — the array a�.
It is guaranteed that the sum of n� over all test cases doesn't exceed 2⋅1052⋅105.
Output
For each test case, output a single integer — the number of subsequences that have exactly k� set bits in their bitwise AND��� value's binary representation. The answer may be large, so output it modulo 109+7109+7. 遗憾的是,出题人想不出一个有趣的故事,所以他只让你解决下面的问题。
给定一个数组a�包含由...组成n�正整数,计算按位的非空子序列的数量AND�否丁子序列中的元素恰好k�在其二进制表示中设置位。答案可能很大,所以输出模数109+7109+7.
回想一下数组的子序列a�是一个序列,可以从a�通过删除一些(可能是零)元素。例如,[1,2,3][1个,2个,3个],[ 3 ][3个],[ 1 , 3 ][1个,3个]是子序列[ 1 , 2 , 3 ][1个,2个,3个], 但[ 3 , 2 ][3个,2个]和[ 4 , 5 , 6 ][4个,5个,6个]不是。
注意一个和一个�否丁表示按位与运算。
Code
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int f[200005][64],n,k,ans;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
cin>>n>>k;
ans=0;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
memcpy(f[i],f[i-1],sizeof(f[i]));
f[i][x]++;
for(int j=0;j<64;j++)
{
f[i][j&x]+=f[i-1][j];
f[i][j&x]%=mod;
}
// cout<<f[i][1]<<" ";
}
if(k==0) cout<<f[n][0]<<"\n";
else
{
for(int i=1;i<64;i++)
{
if(__builtin_popcount(i)==k)
{
ans+=f[n][i];
ans%=mod;
}
}
cout<<ans<<"\n";
}
}
}