#P12819. [NERC 2021] Fancy Stack
[NERC 2021] Fancy Stack
题目描述
Little Fiona has a collection of blocks of various sizes , where is even. Some of the blocks can be equal in size. She would like to put all these blocks one onto another to form a stack.
Let be the sizes of blocks in the stack from top to bottom. Since Fiona is using all her blocks, must be a permutation of . Fiona thinks the stack is if both of the following conditions are satisfied:
- The second block is strictly bigger than the first one, and then each block is alternately strictly smaller or strictly bigger than the previous one. Formally, .
- The sizes of the blocks on even positions are strictly increasing. Formally, (remember that is even).
Two stacks are considered different if their corresponding sequences differ in at least one position.
Fiona wants to know how many different fancy stacks she can build with all of her blocks. Since large numbers scare Fiona, find this number modulo .
输入格式
Each input contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains a single integer --- the number of blocks at Fiona's disposal (; is even). The second line contains integers --- the sizes of the blocks in non-decreasing order ().
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, print the number of ways to build a fancy stack, modulo .
2
4
1 2 3 4
8
1 1 2 3 4 4 6 7
2
4