-->
当前位置:首页 > 题库

PROGRAMMING:Insertion sequence of binary search tree

Luz5年前 (2021-05-10)题库519
Binary search tree is defined as:
*The left subtree contains only elements smaller than the root node;
*The right subtree only contains elements larger than the root node;
*The left and right subtrees are binary search trees.
A binary search tree can have different insertion order. For example, for the following binary search tree
![ figure.png](~/b195dcb4-1d4f-4d13-9094-3fb39e5509cb.png)
The insertion sequence can be '3 2 1 4 6 5',
It can also be ` 3 2 4 1 6 5`
But it can't be '3 2 4 5 6 1'.
The following is a binary search tree traversal sequence, please write a program to find the number of insertion sequence of the tree. Considering that the total number may be very large, please output the result that the total number takes the remainder of $$1000000007 $($$10 ^ 9 + 7 $).
###Input format:
The first line gives an integer $$n $$($$0 < n < = 100 $$), which represents the number of elements in the binary tree;
In the second line, $$n $$positive integers are given, which are separated by spaces, indicating the sequence of binary tree traversal;
###Output format:
Output the total number of inserted sequences on a single line.
###Input example:
```in
six
3 2 1 4 6 5
```
###Output example:
```out
ten
```







answer:If there is no answer, please comment