#P5370. Main Dou Di Winning Hand Count
Main Dou Di Winning Hand Count
Main Dou Di Winning Hand Count
In this problem, we consider a poker game variant called Main Dou Di. The game is played with a modified deck from a standard 54‐card deck: all 3’s are removed so that there remain 50 cards. The deck consists of the cards from 4, 5, 6, 7, 8, 9, 10 (represented as T), J, Q, K, A, 2 and two jokers (small: w and big: W). Each of the non‐joker cards has four copies, while each joker appears exactly once.
Two players are dealt 17 cards each, and the remaining 16 cards are discarded. The allowed card combinations (which are similar but not identical to those in traditional Dou Di Zhu) are listed below, with their definitions provided in ( \LaTeX ) where applicable:
- Single: any single card. For example, 6 or w.
- Pair: two cards of the same rank (note: the two jokers cannot form a pair).
- Triple: three cards of the same rank.
- Triple with Single: three cards of the same rank plus one arbitrary single card. For example, 666w.
- Triple with Pair: three cards of the same rank plus a pair of some other rank. For example, 66699.
- Straight: a sequence of at least five consecutive singles. It must be consecutive in rank according to ( 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 (T) < J < Q < K < A < 2 < w < W ) and cannot contain any 2’s or jokers.
- Consecutive pairs: at least three consecutive pairs, with the same restrictions as the straight.
- Triple Sequence: at least two consecutive triples, with the same restrictions as the straight.
- Four with Two: four cards of the same rank with two additional singles (pairs are not allowed as bonus).
- Airplane with Single Wings: a triple sequence accompanied by the same number of singles, all of different ranks.
- Airplane with Pair Wings: a triple sequence accompanied by the same number of pairs (each pair of a distinct rank).
A few additional notes about the rules:
- There is no concept of a "chain bomb"; for instance, a hand like 444455556666 is interpreted as an airplane with single wings.
- The jokers are distinct, so an airplane may include them (e.g. 333444wW is a valid airplane with single wings).
- There are no bombs – a four‐of‐a‐kind is considered as a triple with a single, and has no bomb effect.
- There is no rocket (i.e. the combination wW is not valid).
The game is played in rounds. In each round, player one (Jiutiao Kelian) leads by playing any legal combination from his hand. Player two (XX Netizen) must then play a combination of the same type that is strictly greater than player one’s combination (the card order is determined by the rules above, with the special rule that for Triple with Single and Triple with Pair, the ranking depends only on the triple part; for Four with Two, it depends on the quadruple; and for airplanes, on the smallest triple in the sequence). If player two cannot respond, the game is lost. The game ends when at least one player has no cards left. The team wins only if both players finish their hands simultaneously; if only one does, it is considered a loss.
Both players know each other’s hands and play optimally. Given XX Netizen’s hand, your task is to count how many different 17-card hands for Jiutiao Kelian will guarantee a win for their team.
Note: The hands of both players and the discarded cards are chosen from the 50-card deck (with no 3’s).
inputFormat
The input is a single line string representing XX Netizen’s 17-card hand. The cards are represented by their characters as described (e.g., 4, 5, 6, 7, 8, 9, T, J, Q, K, A, 2, w, W).
outputFormat
Output a single integer – the number of 17-card hands for Jiutiao Kelian that guarantee a win when both players play optimally.
sample
666789TJQKAAAA222
0