#P6424. [COCI 2008/2009 #2] SETNJA
[COCI 2008/2009 #2] SETNJA
Description
In a binary tree:
- Each node has two children: a left child and a right child.
- If a node is labeled with an integer , then its left child is labeled , and its right child is labeled .
- The root of the tree is labeled .
We traverse the binary tree starting from the root. Each step of the traversal is either jumping to the left child, jumping to the right child, or pausing to rest (staying at the same node).
The traversal process is described by a string consisting of the characters L, R, and P.
Lmeans jump to the left child.Rmeans jump to the right child.Pmeans pause for one step.
The value of is the label of the node we finally reach. For example, the value of LR is , and the value of RPP is .
A traversal is described by L, R, P, and *. Each * can be any of the three actions. For example, L*R may represent LLR, LRR, and LPR. The set ** may represent LL, LR, LP, RL, RR, RP, PL, PR, and PP.
Finally, the total value of for such a traversal is the sum of the values of all possible concrete traversals represented by it.
Compute the total value of for the given traversal description.
Input Format
One line containing a string that describes the traversal.
Output Format
One line containing an integer, the total value of .
P*P
6
L*R
25
**
33
LLLLLRRRRRLLLLLRRRRRLLLLLRRRRRLLLLL
35400942560
Hint
Constraints
- For of the testdata, the input string contains no
*characters. - For of the testdata, the input string contains at most three
*characters. - For of the testdata, the input string length is less than , and each character is only one of
L,R,P,*.
Notes
- This problem is translated from COCI2008-2009 CONTEST #2 SETNJA. Translator: https://www.luogu.com.cn/user/115711
Translated by ChatGPT 5
京公网安备 11011102002149号