#P5370. [PKUSC2018] 主斗地
[PKUSC2018] 主斗地
Description
If you have taken part in NOIP 2015 and PKUWC 2018, you must have a deep impression of a problem called Dou Dizhu. To pay tribute to the classic, we made another card-related problem. In this problem, the hand types are similar to but not exactly the same as Dou Dizhu. We call the poker game in this problem Zhu Dou Di.
Zhu Dou Di is a poker game played with a total of 54 cards: A to K of spades, hearts, clubs, and diamonds, plus the small joker and the big joker, one each. All other ranks have four copies. In Dou Dizhu, the order of ranks is as follows: small joker big joker , and suits do not affect the card order. In each game, a hand consists of cards. Each time, a player may play cards according to the allowed hand types. The first player to play all their cards wins the game. To simplify the problem, we ignore suits, i.e., all cards of the same rank are considered identical.
In this problem, the allowed hand types are ( this part differs from the traditional Dou Dizhu, please be careful ):
| Name | Explanation | Example | Note |
|---|---|---|---|
| Single | A 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 + Single | A triple plus one single card | 666w | |
| Triple + Pair | A triple plus one pair of a different rank | 66699 | |
| Straight | or more consecutive single cards | 3456789 | Cannot contain jokers or 2 |
| Consecutive Pairs | or more consecutive pairs | 33445566 | |
| Consecutive Triples | Two or more consecutive triples | 333444555 | |
| Four + Two | Four cards of the same rank plus two single cards | 444456 444455 | Note that you cannot bring two pairs |
| Plane (single wings) | Consecutive triples plus the same number of single cards whose ranks are pairwise different | 33344455569J | |
| Plane (double wings) | Consecutive triples plus the same number of pairs whose ranks are pairwise different | 3334446699 |
Notes:
- There is no “consecutive bombs” hand type, but a hand like 444455556666 is still playable; it will be treated as a Plane (single wings) hand type, namely 444555666 with wings 456.
- The big joker and the small joker are different ranks, so it is legal for the plane’s wings to include both jokers, e.g., 333444wW.
- It is easy to verify that the above hand type rules are valid: for any legal hand, it has a unique hand type.
- There are no bombs. A bomb will be treated as Triple + Single, and it has no bomb effect, i.e., it cannot beat any hand type.
- There is no rocket. This means wW is no longer a legal hand type.
Two hands belong to the same hand type if and only if they have the same name and contain the same number of cards. Between hands of the same hand type, there is an order:
- For Triple + Single and Triple + Pair, the order depends on the rank of the triple.
- For planes, the order depends on the order of the consecutive triples.
- For Four + Two, the order depends on the rank of the four-of-a-kind.
- For other hand types, the order depends on the largest card in the hand.
Below is the game process of Zhu Dou Di:
- In Zhu Dou Di, there are two players, and they are on the same team. The two players must achieve the game goal together. For convenience, assume the first player is Jiutiao Kelian, and the second player is an “×× netizen”.
- The game uses only one complete deck of cards. At the start of the game, all ’s are thrown away first. Then each side randomly draws cards from the deck, and the remaining cards are discarded. You may think of it as: after shuffling, Jiutiao Kelian takes the first cards, the “×× netizen” takes the next cards, and the remaining cards are thrown away.
- The game consists of several rounds, and each round has two steps:
- Step 1: Jiutiao Kelian chooses any legal hand of any hand type and any size from their current hand and plays it.
- Step 2: The “×× netizen” chooses a hand from their current hand that has the same hand type as and is strictly larger in order, and plays it. If no such hand exists, the game fails.
- After a round ends, if at least one of Jiutiao Kelian and the “×× netizen” has no cards left, the game ends. If both players have no cards left, the game is a win; otherwise it is a failure.
Here is an example:
Suppose Jiutiao Kelian’s cards are 44445556789TJQKwW, and the “×× netizen” has 666789TJQKAAAA222. One winning strategy is:
- Round 1: Jiutiao Kelian plays 4444wW, and the “×× netizen” plays AAAA22.
- Round 2: Jiutiao Kelian plays 6789TJQ, and the “×× netizen” plays 789TJQK.
- Round 3: Jiutiao Kelian plays 555K, and the “×× netizen” plays 6662.
This game strongly tests the coordination between the two players. However, since Jiutiao Kelian and the “×× netizen” cannot understand each other, they decide to play with open hands, i.e., both sides know the other’s cards. Since both players will act according to the optimal strategy, the outcome of the game is already determined at the moment the cards are dealt.
Now you are given the “×× netizen”’s hand. You need to compute how many different possible hands Jiutiao Kelian can have that allow them to win.
Note: the “×× netizen”’s cards and Jiutiao Kelian’s cards come from the same deck, and there are no ’s when dealing.
Input Format
For each test case, input one line: a string of length representing the “×× netizen”’s hand. We use 456789TJQKA2wW to represent each rank of card.
Output Format
For each test case, output an integer representing the answer: the number of Jiutiao Kelian’s hands that satisfy the condition. The answer may be very large, so 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 still considered the same.
556789TJJQKKAA22w
456789TJJQKKAA22w
456789TJQKKKAAA22
193483
0
613897
Hint
For various reasons, this problem uses bundled testdata. There are subtasks in total:
| Subtask ID | Score | Constraint |
|---|---|---|
| 1 | Each rank appears at most times | |
| 2 | Each rank appears at most times | |
| 3 | Each rank appears at most times |
Time limit: 2s.
Memory limit: 512M.
Translated by ChatGPT 5
京公网安备 11011102002149号