#P2456. [SDOI2006] 二进制方程
[SDOI2006] 二进制方程
Description
An equality of the form:
$$\overline{X_1X_2\dots X_n}= \overline{Y_1Y_2\dots Y_m}$$is called a binary equation.
On both sides of a binary equation, each and ( and ) is either a binary digit or , or a variable (a lowercase letter). Each variable represents a binary string of fixed length; this length is called the length of the variable. To solve a binary equation, we assign suitable binary strings to the variables so that, after replacing the variables with their strings (so both sides become binary strings), the equality holds.
Programming task:
For each given equation, compute how many solutions there are in total.
Input Format
The input consists of four lines.
Line 1: , the number of variables. The variables are the first lowercase English letters (for example, if , then the variables are ).
Line 2: positive integers separated by a single space, giving the lengths of the variables in order.
Line 3: the expression on the left-hand side of the equation.
Line 4: the expression on the right-hand side of the equation.
Output Format
A single integer, the total number of solutions for the variables that appear in the equation.
2
4 2
1b1
a
4
5
4 2 4 4 2
1bad1
acbe
16
Hint
Explanation for Sample 1
There are solutions, as follows:
- , .
- , .
- , .
- , .
Explanation for Sample 2
, so the variables are , with lengths: . The equation is .
Therefore, the output is , meaning there are solutions for the variables .
Constraints
, because there are at most variables (the lowercase English letters).
On each side of the equation, the sum of the lengths of digits and variables does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号