#P1229. 遍历问题
遍历问题
Description
We are all familiar with preorder, inorder, and postorder traversals of binary trees. In data structures, a common problem is: given the preorder and inorder traversals of a binary tree, find its postorder traversal; similarly, given the postorder and inorder traversals, you can find its preorder traversal. However, given the preorder and postorder traversals of a binary tree, you cannot determine its inorder traversal. Consider the binary trees in the figure below:

All these binary trees have the same preorder and postorder traversals, but different inorder traversals.
Input Format
Two lines in total. The first line is the preorder traversal of the binary tree, and the second line is the postorder traversal .
It is guaranteed that at least one binary tree satisfies the given information. contain only lowercase letters, and within each string no letter appears more than once.
Output Format
Output the total number of possible inorder traversal sequences. The result does not exceed .
abc
cba
4
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号