#P3158. [CQOI2011] 放棋子
[CQOI2011] 放棋子
Description
On an -row by -column board, place some colored pieces so that each cell contains at most one piece, and pieces of different colors cannot lie in the same row or the same column. How many ways are there?
For example, when , there are two white pieces and one gray piece. The two arrangements on the left below are valid, while the two on the right are invalid.

Input Format
The first line contains three integers , which are the numbers of rows, columns, and colors.
The second line contains positive integers, which are the number of pieces of each color.
Output Format
Output a single line: the remainder when the total number of arrangements is divided by .
4 2 2
3 1
8
Hint
For of the testdata, , , and the total number of pieces .
Translated by ChatGPT 5
京公网安备 11011102002149号