#P3158. [CQOI2011] 放棋子

    ID: 2207 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2011重庆各省省选容斥构造

[CQOI2011] 放棋子

Description

On an mm-row by nn-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 n=m=3n=m=3, 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 n,m,cn,m,c, which are the numbers of rows, columns, and colors.

The second line contains cc 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 109+910^9+9.

4 2 2
3 1
8

Hint

For 100%100\% of the testdata, 1n,m301\le n,m\le 30, 1c101\le c\le 10, and the total number of pieces n×m\le n\times m.

Translated by ChatGPT 5