#P15733. [JAG 2024 Summer Camp #2] Expression Sum
[JAG 2024 Summer Camp #2] Expression Sum
题目描述
You are given a string . Each character in is one of ?
Let be a string formed by replacing each in with one of . Define as follows:
- If is a valid expression, then it is the value obtained by evaluating as an expression.
- If is not a valid expression, then it is .
Compute the sum of for all possible ways to replace each in with one of , and output the result modulo .
A valid expression is defined by the following BNF:
$$\begin{aligned} \texttt{<expression>} &\ ::= \ \texttt{<expression>} \ \texttt{"+"} \ \texttt{<primary>} \ | \ \texttt{<primary>} \\ \texttt{<primary>} &\ ::= \ \texttt{"("} \ \texttt{<expression>} \ \texttt{")"} \ | \ \texttt{<number>} \\ \texttt{<number>} &\ ::= \ \texttt{<nonzero-digit>} \ \texttt{<number-sub>} \ | \ \texttt{<digit>} \\ \texttt{<number-sub>} &\ ::= \ \texttt{<number-sub>} \ \texttt{<digit>} \ | \ \texttt{<digit>} \\ \texttt{<digit>} &\ ::= \ \texttt{"0"} \ | \ \texttt{<nonzero-digit>} \\ \texttt{<nonzero-digit>} &\ ::= \ \texttt{"1"} \ | \ \texttt{"2"} \ | \ \texttt{"3"} \ | \ \texttt{"4"} \ | \ \texttt{"5"} \ | \ \texttt{"6"} \ | \ \texttt{"7"} \ | \ \texttt{"8"} \ | \ \texttt{"9"} \end{aligned}$$输入格式
The input is given in the following format:
- Each character of is one of ?
输出格式
Output the answer.
?1?
46306
20???0+2??
651059511