#P1310. [NOIP 2011 普及组] 表达式的值
[NOIP 2011 普及组] 表达式的值
Description
Define two operations on -bit binary variables:
$$\begin{array}{|c|c|} \hline \qquad\qquad\quad\textsf{Operator}\qquad\qquad\quad & \qquad\qquad\quad\textsf{Operation rule}\qquad\qquad\quad \\ \hline \oplus & \begin{aligned} 0 \oplus 0 &= 0 \\ 0 \oplus 1 &= 1 \\ 1 \oplus 0 &= 1 \\ 1 \oplus 1 &= 1 \\ \end{aligned} \\ \hline \times & \begin{aligned} 0 \times 0 &= 0 \\ 0 \times 1 &= 0 \\ 1 \times 0 &= 0 \\ 1 \times 1 &= 1 \\ \end{aligned} \\ \hline \end{array}$$The precedence of operations is:
-
Evaluate inside parentheses first, then outside.
-
The "×" operation has higher precedence than "⊕", i.e., when evaluating an expression, evaluate "×" before "⊕". For example, when evaluating the expression , compute first, and then perform "⊕" with on the result.
Given an incomplete expression, for example , fill each underscore with the digit or . How many ways are there to make the value of the expression equal to ?
Input Format
There are lines.
The first line contains an integer , the number of operators and parentheses in the given expression, excluding the underscores.
The second line contains a string of characters, consisting only of (, ), +, *. Here ( and ) are the left and right parentheses, and +, * represent the operators and defined above. This line lists, in order, the operators and parentheses in the given expression, excluding variables.
Output Format
Output one line containing a single integer, the number of ways. Note: This number can be very large, so output the result modulo .
4
+(*)
3
Hint
[Explanation of the sample input and output]
The given expression, after including the underscores, is: .
If we fill the underscores with , , or , the value of the expression is , so there are valid fillings.
[Constraints]
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, the input expression contains no parentheses.
Translated by ChatGPT 5
京公网安备 11011102002149号