Time Limit: 2 second(s) | Memory Limit: 32 MB |
OUM is a one unit machine which processes jobs. Since it can't handle heavyweight jobs; jobs needs to be partitioned into units. Initially, all the job information and unit partitions are given as input. Then the machine allocates necessary time slots. And in each time slot it asks the user for the name of the job to be processed. After getting the name; the machine determines the next unprocessed unit of that job and processes that unit in that slot. If there is no such unit, the machine crashes. A job is said to be complete if all the units of that job are complete.
For example, let J_{1} and J_{2} be two jobs each having 2 units. So, OUM will create 4 time slots. Now the user can give J_{1} J_{2} J_{2} J_{1} as input. That means it completes the 1^{st} unit of J_{1} in time slot 1 and then completes the 1^{st} unit of J_{2} in time slot 2. After that it completes the 2^{nd} unit of J_{2} and 2^{nd} unit of J_{1} in time slots 3 and 4 respectively. But if the user gives J_{1} J_{1} J_{2} J_{1 }as input, the machine crashes in time slot 4 since it tries to process 3^{rd} unit of J_{1} which is not available.
Now, Sam is the owner of a software firm named ACM and he has n jobs to complete using OUM. He wants to complete Job_{i} before Job_{i+1} where 1 ≤ i < n. Now he wants to know the total number of ways he can complete these jobs without crashing the OUM. He assigned you for this task. Two ways are different if at t^{th} slot one processed a unit of Job_{i} and another processed a unit of Job_{j} where i ≠ j. For the example above, there are three ways:
J_{1} J_{1} J_{2} J_{2}
J_{1} J_{2} J_{1} J_{2}
J_{2} J_{1} J_{1} J_{2}
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with an integer n (1 ≤ n ≤ 1000). The next line contains n space separated positive integers k_{1}, k_{2}, k_{3} ... k_{n}. Where, k_{i} denotes the number of units for the i^{th} job. You can assume that total number of units for all the jobs in any case is not greater than 10^{6}.
For each case, print the case number and the result modulo 1000,000,007.
Sample Input |
Output for Sample Input |
2 2 2 2 3 2 2 3 |
Case 1: 3 Case 2: 45 |
Developed and Maintained by
JANE ALAM JAN |
Copyright © 2012
LightOJ, Jane Alam Jan |