| ACPC Kickoff 2025 |
|---|
| Finished |
You have a parking lot of $$$n$$$ parking spots and a queue of cars with $$$n$$$ cars numbered from $$$1$$$ to $$$n$$$, where the first car in the queue is $$$1$$$ and the last is $$$n$$$ (i.e. they are sorted in increasing order).
In this parking lot, there are parking spots reserved for specific cars, so for the $$$i$$$-$$$th$$$ parking spot if $$$a_i=0$$$ then there are no reservations for this spot and anyone can park here, else if ($$$1 \le a_i \le n$$$) then this spot is reserved for the $$$a_i$$$-$$$th$$$ car only and no other car can park here, note that it is reserved for $$$a_i$$$-$$$th$$$ car but that car doesn't necessarily have to park here.
Cars come to the parking lot one by one starting from the $$$1$$$-$$$st$$$ car and finishing with the $$$n$$$-$$$th$$$ car and each car has to park in one of the $$$n$$$ parking spots. Each parking spot should have exactly one car.
Unfortunately, all $$$n$$$ cars drivers are girls, and as you know, girls are not good at driving, so a car $$$j$$$ cannot park in the $$$i$$$-$$$th$$$ parking spot if ($$$2 \le i \le n-1$$$) and there are cars that already parked in spots $$$i-1$$$ and $$$i+1$$$, otherwise car $$$j$$$ can park safely.
For example, if $$$a = [0,1,0,0,0]$$$ then possible valid arrangements for cars are $$$[2,1,3,4,5]$$$ and $$$[3,1,2,4,5]$$$, while $$$[5,4,3,2,1]$$$ is not valid because the $$$2$$$-$$$nd$$$ spot is reserved for car $$$1$$$ while car $$$4$$$ parked there, and $$$[3,1,4,2,5]$$$ is not valid because car $$$4$$$ parked in $$$3$$$-$$$rd$$$ spot while $$$2$$$-$$$nd$$$ and $$$4$$$-$$$th$$$ spot where already filled.
Since you are obsessed with the number of possible arrangements of anything, you are interested in knowing how many ways are there possible to arrange the cars in the parking lot.
Since the answer can be very large, print it modulo $$$10^9+7$$$.
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of test cases. The description of the test cases follows.
The first line of each test case contains one integer $$$n$$$ $$$(1 \le n \le 10^3)$$$ — the number of cars.
The second line contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ $$$(0 \le a_i \le n)$$$ — if $$$a_i=0$$$, it means that the $$$i$$$-$$$th$$$ spot is not reserved to anyone; else it means that the $$$i$$$-$$$th$$$ spot is reserved for the $$$a_i$$$-$$$th$$$ car.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^3$$$.
For each test case on a single line, print one integer — the number of permutations modulo $$$10^9+7$$$.
4 2 1 2 2 1 1 3 0 1 0 5 0 1 0 0 0
1 0 2 4
| Name |
|---|


