Sadness Everywhere

5

4 votes
Bitmask
Problem

Lets define three functions:
F(P,Q)= (¯P&Q)&(¯P|Q)  
G(A,B,C)=(B&F(A,C))|(A&F(B,C))
H(A,B)=max(G(A,B,C)) , (maximum possible value of G(A,B,C), where C can be any whole number).

Here, & represents bitwise "and", | represents bitwise "or", and ¯A ,represents bitwise "not" of A.

Suppose, we are given an array a of size n, with elements a1, a2, a3, …an.
We define sadness of this array as:
H(.(H(H(H(a1,a2),a3),.),an1),an).

You are given an array ‘A’ of size ‘N’, and a number ‘K’ , Your task is to find the number of subsequence whose sadness is greater than or equal to K. (Sadness of empty set would be 0, and sadness of singleton set would be the only element itself).

A sequence "a" is a subsequence of an array "b" if "a" can be obtained from "b" by deleting some (possibly, zero or all) elements.

Input:

- First line of input contains ‘T’, the number of test case.
- First line of each test case contains two integer, ‘N’ and ‘K’, denoting the size of array, and the number ‘K’.
- Second line of each test case contains N space separated integers, A1, A2, A3, …AN, the elements of the array.

Output:

For each test case, print a single line containing one integer – the answer to each test case (modulo 109 + 7, as answer could be very large).

Constraints:

1<=T<=10
1<=N<=105
0<=Ai<230
0<=K<220

40% of the input file has:

1<=T<=10
1<=N<=10000
0<=Ai<210
0<=k<210

Sum of N over all test case does not exceed 2*104

Sample Input
1 
5 4
1 2 3 4 5
Sample Output
16
Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?