#P8420. [THUPC 2022 决赛] 匹配

[THUPC 2022 决赛] 匹配

Problem Description

A “match item” is defined as a string of length LL, where each position is either 0\texttt{0} or 1\texttt{1}. Now there are NN such “match items”. We want to design a “plan”, which is also a string of length LL, and each position is either 0\texttt{0} or 1\texttt{1}.

For each “match item”, define its error value as the number of positions where the “plan” differs from the “match item”. For example, if the “match item” is 101\texttt{101} and the “plan” is 000\texttt{000}, then the first and third positions are different, so the error value of this “plan” for that “match item” is 22.

We want to find a “plan” that minimizes the sum of error values over these NN “match items”. In addition, there are MM distinct forbidden “plans”, and the “plan” we find must not be one of the forbidden “plans”.

Input Format

The first line contains three positive integers N,M,LN, M, L.

Then there are NN lines, each being a string of length LL. After that, there are MM lines, each being a string of length LL.

Output Format

Output one integer, the minimum possible sum of error values over the NN “match items” achieved by a valid “plan”.

4 1 4
0000
1000
1100
1010
1000

5

2 4 4
0000
0000
0000
1000
0100
0010
2

Hint

It is guaranteed that 1N10001 \le N \le 1000, 1Mmin(1000,2L1)1 \le M \le \min(1000, 2^L - 1), 1L10001 \le L \le 1000.

Translated by ChatGPT 5