#P5645. [PKUWC2018] 斗地主
[PKUWC2018] 斗地主
Background
Dou Dizhu is a poker game played with a full deck of cards: ranks from A to K in four suits (spades, hearts, clubs, diamonds), plus two Jokers (one small Joker and one big Joker). Each Joker appears once, and every other rank appears four times. In Dou Dizhu, the rank order is defined as follows: small Joker big Joker. Suits do not affect the comparison of card ranks. In each game, a hand consists of cards. On each turn, a player may play cards according to the allowed patterns. The first player to play all cards in their hand wins. To simplify the problem, we ignore suits, meaning that all cards of the same rank are considered identical.
In this problem, the allowed patterns are ( this part is different from standard Dou Dizhu, please note ):
| Name | Explanation | Example | Note |
|---|---|---|---|
| Rocket | Two Jokers | ♂♀ | |
| Bomb | Four cards of the same rank | 6666 | |
| Single | One single card | 6 | A single Joker is also a Single. |
| Pair | Two cards of the same rank | 66 | The two Jokers do not form a Pair. |
| Triple | Three cards of the same rank | 666 | |
| Triple with Single | A Triple plus one Single of a different rank | 666♂ | A Bomb is not a Triple with Single. |
| Triple with Pair | A Triple plus one Pair of a different rank | 66699 | |
| Straight | A sequence of at least consecutive Singles | 3456789 | Cannot contain Jokers or 2. |
| Consecutive Pairs | A sequence of at least consecutive Pairs | 33445566 | |
| Consecutive Triples | A sequence of at least consecutive Triples | 333444555 | |
| Four with Two | Four cards of the same rank plus two Singles | 444456 444455 | |
| Plane (single wings) | Consecutive Triples plus the same number of Singles whose ranks are pairwise distinct | 33344455569J | |
| Plane (double wings) | Consecutive Triples plus the same number of Pairs whose ranks are pairwise distinct | 3334446699 |
Notes:
- There is no pattern called “consecutive bombs”, but a hand like 444455556666 can still be played. It will be treated as a Plane (single wings): 444555666 with wings 456.
- The big Joker and the small Joker are different ranks, so a plane can legally take both Jokers as wings, for example 333444♂♀.
- It can be verified that the above rules are well-defined: for any legal play, it has a unique pattern type.
Two plays are of the same pattern type if and only if they have the same name and contain the same number of cards. Plays of the same pattern type can be compared in strength (Rocket is unique and does not need comparison):
- For Triple with Single and Triple with Pair, the strength depends on the rank of the Triple.
- For Planes, the strength depends on the strength of the Consecutive Triples part.
- For Four with Two, the strength depends on the rank of the four-of-a-kind.
- For all other pattern types, the strength depends on the maximum rank among the cards in the play.
The gameplay process of Dou Dizhu is described as follows ( this part is exactly the same as standard Dou Dizhu ):
- In Dou Dizhu, the three players are split into two sides: one player is the Landlord, and the other two are Farmers. The Landlord has cards, and each Farmer has cards (together forming exactly one full deck).
- The game proceeds in multiple rounds. In each round, the winner of the previous round plays first (in the first round, the Landlord plays first). Then players take turns in order (you may imagine the three players sitting in a circle, playing clockwise).
- The first player of a round may play any legal pattern of any strength. Then, when it is a player’s turn, they may choose:
- Play nothing (pass).
- Play a strictly stronger play of the same pattern type as the most recent play in this round.
- If the most recent play is not a Bomb or Rocket, play any Bomb of any strength.
- Play a Rocket.
- In a round, if after a player plays, the other two players both choose to pass, the round ends. That player becomes the winner of this round and starts the next round.
- At any time, if a player has played all cards in their hand, the game ends and that player wins.
- If the Landlord wins and neither Farmer has played any card, then the Landlord is said to have achieved “Spring”.
Problem Description
Now three people are playing Dou Dizhu. If the Landlord achieves Spring, then the Landlord is considered the winner; otherwise, even if the Landlord plays all their cards first, it is still considered a win for the Farmers. Assume all three players act with optimal decisions.
You are given cards. Ask how many possible initial hands of the Landlord contain these cards, and no matter how the Farmers’ cards are distributed, the Landlord is guaranteed to achieve Spring.
Input Format
The first line contains an integer indicating the number of test cases.
For each test case, one line is given. The first integer is , the number of fixed cards, followed by space-separated integers describing each fixed card.
In particular, we use to represent rank A, for rank J, for rank Q, for rank K, for the small Joker, and for the big Joker. The input is guaranteed to be valid, meaning that the count of each rank will not exceed its count in a full deck.
Output Format
For each test case, output one integer, the number of Landlord hands that satisfy the condition. The answer may be very large; output it modulo .
Note: In this problem we ignore suits. If two hands have exactly the same multiset of ranks but different suits, they are considered the same.
6
20 1 2 2 3 4 5 6 7 8 8 9 10 11 11 12 13 13 13 13 15
20 1 1 2 2 3 4 5 6 7 8 9 10 11 12 12 12 12 13 13 14
20 1 2 2 3 3 4 5 6 7 7 7 7 8 9 10 10 11 12 13 15
20 1 2 3 4 4 5 6 7 8 9 10 11 11 12 13 13 13 13 14 15
3 3 3 3
4 3 3 3 3
1
0
1
1
4790
1670
Hint
Sample Explanation
For the first sample, we can see that the Farmers cannot have a Bomb or Rocket, so the Landlord can first play (clearly neither Farmer can beat it), then play , then play the big Joker, then play , and finally play .
| ID | ||
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 | ||
| 9 | ||
| 10 |
Translated by ChatGPT 5