P28769 [洛谷] [HNOI/AHOI2018] Treasure Hunt Game
省选
题目描述

Problem Description

A university holds an annual Mystery Hunt event where players solve puzzles based on clues to find the treasure's location. The winning team from the previous year gets the chance to set the puzzles for the current year.

As a freshman, you are very interested in this event. You walk through a long corridor of the teaching building from west to east every day. This corridor is so long that it is humorously called the infinite corridor. One day, while passing through this corridor, you notice that the walls are hidden with $n$ equally long binary numbers, each of length $m$. You record these numbers from west to east, forming an array of $n$ binary numbers $a_1, a_2, ..., a_n$.

Soon, in the latest issue of the Voo Doo magazine, you find $q$ binary numbers $r_1, r_2, ..., r_q$, each also of length $m$.

You quickly realize the meaning of these numbers.

Keeping the order of the elements in the array $a_1, a_2, ..., a_n$ unchanged, you can insert $\land$ (bitwise AND) or $\lor$ (bitwise OR) between them. For example: $11011 \land 00111 = 00011$, $11011 \lor 00111 = 11111$.

You need to insert $n$ operators, exactly one between each pair of adjacent numbers, and one at the left side of the first number. If we add a 0 to the left of the first operator, this forms an expression, which we can evaluate. As usual, the evaluation order is from left to right. Interestingly, the puzzle setter has already told you the possible set of values for this expression—the binary numbers in the Voo Doo magazine $r_1, r_2, ..., r_q$. The method to solve the puzzle is to calculate for each value $r_i$ in $r_1, r_2, ..., r_q$, how many ways to insert these $n$ operators such that the expression evaluates to $r_i$.

However, the infinite corridor is indeed very long, which means the data range could be very large. Therefore, the answer could also be very large, but you find that due to the puzzle's specificity, you only need to find the answer modulo $1000000007$.

Input Format

The first line contains three numbers $n, m, q$, as described in the problem.

The next $n$ lines each contain a binary number of length $m$, with the leftmost bit being the most significant, representing $a_i$.

The next $q$ lines each contain a binary number of length $m$, with the leftmost bit being the most significant, representing $r_i$.

Output Format

Output $q$ lines, each containing a number, where the $i$-th line represents the answer for $r_i$.

Sample Input and Output

Input Sample #1

5 5 1
01110
11011
10000
01010
00100
00100

Output Sample #1

6

Input Sample #2

10 10 3
0100011011
0110100101
1100010100
0111000110
1100011110
0001110100
0001101110
0110100001
1110001010
0010011101
0110011111
1101001010
0010001001

Output Sample #2

69
0
5

Notes/Hints

For $10\%$ of the data, $n \le 20, m \le 30, q = 1$;

For another $20\%$ of the data, $n \le 1000, m \le 16$;

For another $40\%$ of the data, $n \le 500, m \le 1000$;

For all data, $1 \leq n \leq 1000, 1 \leq m \leq 5000, 1 \leq q \leq 1000$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 5 1 01110 11011 10000 01010 00100 00100
样例输出
6