P2540 [NOIP 2015 Senior] Dou Dizhu Enhanced Version
Description
Niuniu has recently become obsessed with a card game called Dou Dizhu. Dou Dizhu is a poker game played with a deck of $54$ cards: $A$ through $K$ in Spades, Hearts, Clubs, and Diamonds, plus the two Jokers. In Dou Dizhu, the card ranks are ordered by their numbers as follows: $3
Input Format
The first line contains $2$ positive integers $T, n$ separated by a space, representing the number of hands and the number of cards in each hand.
Then follow $T$ groups of data. For each group, there are $n$ lines, each containing a pair of non-negative integers $a_i, b_i$, representing one card, where $a_i$ is the card rank and $b_i$ is the suit, separated by a space. Specifically, we use $1$ to represent rank $A$, $11$ for $J$, $12$ for $Q$, and $13$ for $K$; Spades, Hearts, Clubs, and Diamonds are represented by $1$–$4$ respectively; the small Joker is represented as `0 1`, and the big Joker as `0 2`.
Output Format
Output $T$ lines. Each line contains one integer, the minimum number of plays needed to play out the $i$-th hand.
Explanation/Hint
#### Sample 1 Explanation
There is $1$ hand containing $8$ cards: Diamonds $7$, Diamonds $8$, Spades $9$, Diamonds $10$, Spades $J$, Spades $5$, Diamonds $A$, and Spades $A$. You can play them out in $3$ moves by playing a single straight (Diamonds $7$, Diamonds $8$, Spades $9$, Diamonds $10$, Spades $J$), a single card (Spades $5$), and a pair (Spades $A$ and Diamonds $A$).
#### Constraints and Notes
For the first $20$ test points, the scales of the number of hands $T$ and the number of cards $n$ are as follows:

The testdata does not guarantee that all hands are randomly generated.
Translated by ChatGPT 5