Bob and K - Subset

3.6

16 votes
Basic Programming, Basics of Implementation, Hash Maps, Implementation, Medium
Problem

You are given an array a of size n consisting of integers. Now, you need to find the number of distinct integers x, such that there exists a sequence of distinct indices  i1<i2<...<im,1mk  and   a[i1] or a[i2] or ... or a[im]=x

Here or represents the bitwise OR operator.  

Input

First line of the each input will contain two space seperated integers n and k denoting the size of the array and maximum size of the subset, respectively.

Next line will contain n spaced integers denoting elements of the array.

Constraint

1n1000

1k20

1a[i]2047

Output

Output will consists of a single integer denoting the number of unique integers that can be formed by taking Bitwise OR  of every subset of size less than or equal to k.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Array is having 3 integers: 1, 2 and 4.
Subsets having size less than or equal to 2 is {{1},{2},{4},{1,2},{1,4},{2,4}}.
Bitwise OR of the subsets thus obtained is {1,2,4,3,5,6}.
Thus total unique intgers formed by taking bitwise OR of all subsets of size less than or equal to 2 is 6.

Editor Image

?