Generate Optimal Key
InterviewTime limit2sMemory limit2048 MB
Given n binary patterns and m forbidden keys of length L, find the non-forbidden binary key with the smallest total Hamming distance to all patterns.
- Level
Medium6 of 10
- Topics
- Greedy, Heap, Bit manipulation
- Solved
- No attempts yet
Problem
A pattern is a binary string of length . Given patterns, we want to find a key, which is also a binary string of length .
For a given pattern and a given key, the error value is the number of positions where the key differs from the pattern. For example, if the pattern is 101 and the key is 000, the first and third positions differ, so the error value is .
We want to choose a key that minimizes the sum of the error values between the key and the given patterns. There are also distinct forbidden keys, and the chosen key cannot be one of them.
Input
The first line contains three integers , , and (; ; ).
Each of the next lines contains a pattern, a binary string of length .
Each of the next lines contains a forbidden key, a binary string of length . All forbidden keys are distinct.
Output
Print a single integer: the minimum sum of error values over all non-forbidden keys and the given patterns.