Interesting Numbers
Time limit3sMemory limit1024 MB
Given n integers and k, find the longest subsequence in which the XOR of every pair of elements is at most k.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Trie, Hash map
- Solved
- No attempts yet
Problem
The bitwise exclusive or, or simply XOR, is an operation denoted by that works on two integers by XOR-ing their corresponding bits. If denote the -th binary digit of , , and , where , then .
You are given a positive integer . A sequence of integers is interesting if the XOR of any two of its elements is less than or equal to .
Given a sequence , determine the largest possible length of an interesting subsequence. A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements.
Input
The first line contains the number of test cases (). The descriptions of the test cases follow.
The first line of each case contains two integers and (, ), the length of the sequence and the upper bound on the maximum XOR of its two elements.
The second line contains nonnegative integers (), the given sequence.
The sum of over all test cases does not exceed , and the sum of over all test cases does not exceed .
Output
For every test case, output a single integer, the maximum possible length of an interesting subsequence of the given sequence.
Hint
The elements 3, 9, 10, and 3 form an interesting subsequence, since the XOR of every pair is at most 11. For example, . No subsequence of five elements has this property. For example, is not interesting because .