How many binary sequences
Time limit3sMemory limit256 MB
Find the smallest set of length-K binary strings so each given 0-1-2 string with at most two ones is the sum of two members at Hamming distance at most two.
- Level
Medium7 of 10
- Topics
- Brute force, Bit manipulation
- Solved
- No attempts yet
Problem
You are given a set of binary sequences of length . Every element of is a sequence of values, each of them or .
An integer sequence is built by this process.
- Pick a sequence from .
- Pick a sequence from with . Here is the Hamming distance of the two sequences, the number of positions where the two values differ. For example, and . You may pick the same element as both and .
- Set .
For example, can be built from and .
You are given integer sequences built this way. Among all sets that can build all of them, find one with the fewest elements and print how many elements it has.
Input
The first line contains and , separated by one space. (, )
Each of the next lines contains one sequence . The -th character of the -th line is the value of , and there is no separator between characters. Each value is , , or , and each line contains at most two s, so every given can be built by the process above.
Output
Print the minimum number of elements of the set .