#P10112. [GESP202312 八级] 奖品分配
[GESP202312 八级] 奖品分配
Background
Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1140.
Problem Description
There are students in the class, with student IDs from to . There are types of prizes to be distributed to these students. The -th type of prize has a total of items ().
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 (i.e., ).
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 .
There are classes facing the prize distribution problem, and you need to solve them one by one.
Input Format
The first line contains an integer , which represents the number of classes.
In the next lines, each line contains several positive integers separated by single spaces. First come two positive integers , followed by positive integers . It is guaranteed that .
Output Format
Output lines. Each line contains one integer, which is the number of prize distribution plans for that class modulo .
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 -st class, students with IDs can receive prizes in order, or in order, or in order, so there are plans in total.
For the -nd class, students with IDs can receive prizes in order, or in order, or in order, or in order, so there are plans in total.
For the -rd class, you can assign the prize with ID to any one of the students, giving choices; then assign the prize with ID to any one of the remaining students, giving choices; finally, the remaining students naturally receive prize . Therefore, the number of plans is .
Constraints
For of the test points, .
For another of the test points, .
For all test points, ; ; .
Translated by ChatGPT 5