#P1310. [NOIP 2011 普及组] 表达式的值

    ID: 308 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>字符串动态规划,dp2011NOIp 普及组

[NOIP 2011 普及组] 表达式的值

Description

Define two operations on 11-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:

  1. Evaluate inside parentheses first, then outside.

  2. The "×" operation has higher precedence than "⊕", i.e., when evaluating an expression, evaluate "×" before "⊕". For example, when evaluating the expression AB×CA \oplus B \times C, compute B×CB \times C first, and then perform "⊕" with AA on the result.

Given an incomplete expression, for example _+(__)\_+(\_ * \_), fill each underscore with the digit 00 or 11. How many ways are there to make the value of the expression equal to 00?

Input Format

There are 22 lines.

The first line contains an integer LL, the number of operators and parentheses in the given expression, excluding the underscores.

The second line contains a string of LL characters, consisting only of (, ), +, *. Here ( and ) are the left and right parentheses, and +, * represent the operators \oplus and ×\times 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 1000710007.

4
+(*)

3

Hint

[Explanation of the sample input and output]

The given expression, after including the underscores, is: _+(__)\_+(\_ * \_).

If we fill the underscores with (0,0,0)(0,0,0), (0,1,0)(0,1,0), or (0,0,1)(0,0,1), the value of the expression is 00, so there are 33 valid fillings.

[Constraints]

For 20%20\% of the testdata, 0L100 \le L \le 10.

For 50%50\% of the testdata, 0L1,0000 \le L \le 1{,}000.

For 70%70\% of the testdata, 0L10,0000 \le L \le 10{,}000.

For 100%100\% of the testdata, 0L100,0000 \le L \le 100{,}000.

For 50%50\% of the testdata, the input expression contains no parentheses.

Translated by ChatGPT 5