#P1497. 木牛流马

木牛流马

Description

Kongming excitedly invited Pang Tong to visit. Intending to challenge him, Kongming placed kk Wooden Ox and Flowing Horse pieces on a large n×nn \times n tiled grid and painted them in colors. He asked Pang Tong to count how many different valid layout configurations there are.

Input Format

First line: n,k,hn, k, h (n20n \le 20, hh is the number of colors).

The next hh lines give the quantity of each color.

Output Format

The total number of valid layouts.

4 4 1
4

24

Hint

No big integer is needed. Moreover, Kongming stipulates that the grid cannot be flipped; that is, if two layouts become the same after a flip, they are still counted as two.

Translated by ChatGPT 5