#P10112. [GESP202312 八级] 奖品分配

[GESP202312 八级] 奖品分配

Background

Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1140.

Problem Description

There are NN students in the class, with student IDs from 00 to N1N-1. There are MM types of prizes to be distributed to these students. The ii-th type of prize has a total of aia_i items (i=0,1,,M1i=0,1,\cdots,M-1).

By coincidence, the number of prizes is neither too many nor too few: each student can receive exactly one prize, and the number of prizes left in the end is at most 11 (i.e., Na0+a1++aM1N+1N\le a_0+a_1+\cdots+a_{M-1}\le N+1).

Now, please find the number of possible prize distribution plans for each class. A plan means assigning each student a prize type.

If at least one student receives a different type of prize, it is considered a different plan. For convenience, you only need to output the result modulo 109+710^{9}+7.

There are TT classes facing the prize distribution problem, and you need to solve them one by one.

Input Format

The first line contains an integer TT, which represents the number of classes.

In the next TT lines, each line contains several positive integers separated by single spaces. First come two positive integers N,MN,M, followed by MM positive integers a0,a1...aM1a_0,a_1...a_{M-1}. It is guaranteed that Na0+a1++aM1N+1N \le a_0+a_1+\cdots+a_{M-1} \le N+1.

Output Format

Output TT lines. Each line contains one integer, which is the number of prize distribution plans for that class modulo 109+710^{9}+7.

3
3 2 1 2
3 2 1 3
5 3 1 3 1 
3
4
20
5
100 1 100
100 1 101
20 2 12 8
123 4 80 20 21 3
999 5 101 234 499 66 99
1
1
125970
895031741
307187590

Hint

Sample Explanation 1

For the 11-st class, students with IDs 0,1,20,1,2 can receive prizes 0,1,10,1,1 in order, or 1,0,11,0,1 in order, or 1,1,01,1,0 in order, so there are 33 plans in total.

For the 22-nd class, students with IDs 0,1,20,1,2 can receive prizes 0,1,10,1,1 in order, or 1,0,11,0,1 in order, or 1,1,01,1,0 in order, or 1,1,11,1,1 in order, so there are 44 plans in total.

For the 33-rd class, you can assign the prize with ID 00 to any one of the 55 students, giving 55 choices; then assign the prize with ID 22 to any one of the remaining 44 students, giving 44 choices; finally, the remaining 33 students naturally receive prize 11. Therefore, the number of plans is 5×4=205 \times 4 = 20.

Constraints

For 30%30\% of the test points, N10N \le 10.

For another 30%30\% of the test points, M=2M=2.

For all test points, N1000N \le 1000; T1000T \le 1000; M1001M \le 1001.

Translated by ChatGPT 5