#P5371. [SNOI2019] 纸牌
[SNOI2019] 纸牌
Description
There is a deck of cards. There are types of cards, labeled , and each type has cards. Therefore, the deck contains a total of cards.
Three consecutive cards or three identical cards can form a set. If a multiset of cards can be divided into several (possibly zero) sets, then it is called a winning hand.
You have drawn some initial cards from the deck. Now you want to pick some cards to form a winning hand. How many different winning hands can you form? Output the answer modulo . That is, based on the initial cards, you may select some additional cards (or select none).
Two groups of cards are considered the same if and only if, for every card type, the quantities of that type in the two groups are the same.
Input Format
The first line contains two integers , representing the number of card types and the number of cards of each type.
The second line contains one integer , representing the number of types present in the initial cards.
The next lines each contain two integers , meaning that there are cards of type in the initial cards. The values are given in strictly increasing order.
Output Format
Output one line with one non-negative integer, the answer modulo .
3 3
0
10
9 4
9
1 3
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 3
3521
Hint
Sample Explanation 1
All valid choices are as follows:
- (choose no cards)
Constraints
For all testdata, , , and . Note that and may be .
- For of the data, and .
- For another of the data, and .
- For another of the data, and .
- For another of the data, .
- For another of the data, .
- For the remaining of the data, there are no special restrictions.
Translated by ChatGPT 5
京公网安备 11011102002149号