纯数题 1≤i≤n, fi=max{a1,a2,…,ai}; 1≤i≤n, gi=min{a1,a2,…,ai}; 1≤i≤n, hi=fi−gi. 数列a是一个排列,问多少种排列方式满足h数列。
DreamGrid has an interesting permutation of 1,2,…,n denoted by a1,a2,…,an. He generates three sequences f, g and h, all of length n, according to the permutation a in the way described below:
For each 1≤i≤n, fi=max{a1,a2,…,ai}; For each 1≤i≤n, gi=min{a1,a2,…,ai}; For each 1≤i≤n, hi=fi−gi. BaoBao has just found the sequence h DreamGrid generates and decides to restore the original permutation. Given the sequence h, please help BaoBao calculate the number of different permutations that can generate the sequence h. As the answer may be quite large, print the answer modulo 109+7.
The input contains multiple cases. The first line of the input contains a single integer T (1≤T≤20000), the number of cases.
For each case, the first line of the input contains a single integer n (1≤n≤105), the length of the permutation as well as the sequences. The second line contains n integers h1,h2,…,hn (1≤i≤n,0≤hi≤109).
It’s guaranteed that the sum of n over all cases does not exceed 2⋅106.
For each case, print a single line containing a single integer, the number of different permutations that can generate the given sequence h. Don’t forget to print the answer modulo 109+7.
3 3 0 2 2 3 0 1 2 3 0 2 3
2 4 0
For the first sample case, permutations {1,3,2} and {3,1,2} can both generate the given sequence.
For the second sample case, permutations {1,2,3}, {2,1,3}, {2,3,1} and {3,2,1} can generate the given sequence.