Problem S. The Number of the Same BST
时间限制 1000 ms
内存限制 64 MB
Many people knows binary search tree. The keys in a binary search tree are always stored in such a way as to satisfy the BST property:
Let x be a node in a binary search tree. If y is a node in the left subtree of x, then key[y] <= key[x]. If y is a node in the right subtree of x, then key[y] > key[x].
For example,
It is a binary search tree. And it can be built by inserting the elements of vector A <12, 6, 3, 18, 20, 10, 4, 17, 20> sequentially. But it can also be built by the vector B <12, 18, 17, 6, 20, 3, 10, 4, 20>.
Now given a vector X, then you may get a binary search tree from X. Your job is to calculate how many different vectors can build the same binary search tree. To make it easy, you should just output the number of different vectors mod 9901.
输入数据
输出数据
For each test case, print a line with a single integer, which is the number of different vectors mod 9901.
样例输入
复制
3
2 1 3
9
5 6 3 18 20 10 4 17 20
0
样例输出
$ Mathjax font initiator $