#P13676. [GCPC 2023] Kaldorian Knights
[GCPC 2023] Kaldorian Knights
题目描述
The king of Kaldoria traditionally celebrates his birthday by inviting the knights of his realm to a big jousting tournament, and every noble house participates by sending their best knights to win fame and glory. At the end of the tournament, the king does not only choose a winner but ranks all knights from worst to best.
:::align{center} Painting of a medieval tournament, Codex Manesse. :::
The number of knights belonging to house is denoted by . Each knight serves at most one house. There can be knights who do not serve any house. The houses are ordered by their influence in the kingdom (with the first one being the most influential). If the knights of the most powerful house take the last places in the tournament, the house will incite a revolt against king and crown. The members of the second most influential house are not that powerful. Even if all its knights end up at the bottom of the ranking, it would be considered a strong provocation but the house would not be able to start a revolt. However, if the last places are taken by all the knights of the two most influential houses combined, then the two houses will unite and start fighting the king. More generally, if the knights of the most powerful houses occupy the last places in the tournament, they will unite and incite a revolt.
Of course, a revolt has to be avoided at all cost. Knowing that the king often chooses the ranking spontaneously and without too much consideration, the chief mathematician of the crown has been tasked with analysing how many rankings will not lead to a revolt.
输入格式
The input consists of:
- One line with integers () and (), the number of knights and the number of houses.
- lines, with the th line containing an integer (), denoting the number of knights from house . Note that every house is represented by at least one knight.
It holds that .
输出格式
Output the number of rankings that do not lead to a revolt. As this number can be quite large, it should be output modulo .
3 0
6
4 1
3
18
4 2
2
1
16