Problem 8

All submissions for this problem are available.
There are N cards on the table and each has a number between 0 and N. Let us denote the number on the ith card by c_{i}. You want to pick up all the cards. The ith card can be picked up only if at least c_{i} cards have been picked up before it. (As an example, if a card has a value of 3 on it, you can't pick that card up unless you've already picked up 3 cards previously) In how many ways can all the cards be picked up?
Input:
The first line contains the number of test cases T. T test cases follow. Each case contains an integer N on the first line, followed by integers c_{i},...,c_{N} on the second line.
Output:
Output T lines one corresponding to each test case containing the required answer for the corresponding test case. As the answers can be very big, output them modulo 1000000007.
Sample Input:
3
3
0 0 0
3
0 0 1
3
0 3 3
Sample Output:
6
4
0
Sample Explanations:
For the first case, the cards can be picked in any order, so there are 3! = 6 ways.
For the second case, the cards can be picked in 4 ways: {1,2,3}, {2,1,3}, {1,3,2}, {2,3,1}.
For the third case, no cards can be picked up after the first one, so there are 0 ways to pick up all cards.
Constraints:
1 <= T <= 10
1 <= N <= 50000
0 <= c_{i} <= N
Author:  mayankj08 
Tags  mayankj08 
Date Added:  1032012 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, GO, NODEJS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 