P2668 [NOIP 2015 Senior] Dou Dizhu

Background

NOIP 2015 Day 1 T3.

Description

Niuniu has recently become obsessed with a card game called Dou Dizhu. Dou Dizhu is a card game played with a standard deck consisting of spades, hearts, clubs, and diamonds from $A$ to $K$, plus the two jokers, for a total of $54$ cards. In Dou Dizhu, the rank order of the cards is represented by their face values as follows: $3

Input Format

The first line contains two positive integers $T, n$ separated by a space, representing the number of hand sets and the number of cards in each hand. Then follow $T$ groups of data. Each group contains $n$ lines, each line containing a pair of nonnegative integers $a_i, b_i$ representing a card, where $a_i$ is the rank and $b_i$ is the suit, separated by a space. Specifically, we use $1$ to represent rank $A$, $11$ to represent rank $J$, $12$ to represent rank $Q$, and $13$ to represent rank $K$; spades, hearts, clubs, and diamonds are represented by $1$–$4$, respectively; the small joker is represented by `0 1`, and the big joker is represented by `0 2`.

Output Format

Output $T$ lines. Each line contains an integer representing the minimum number of plays needed to play out the $i$-th hand set.

Explanation/Hint

Sample 1 explanation: There is $1$ hand set with $8$ cards: diamond $7$, diamond $8$, spade $9$, diamond $10$, spade $J$, spade $5$, diamond $A$, and spade $A$. You can finish in $3$ plays by playing a straight of singles (diamond $7$, diamond $8$, spade $9$, diamond $10$, spade $J$), a single (spade $5$), and a pair (spade $A$ and diamond $A$). For different test points, we define the scales of the number of hand sets $T$ and the number of cards $n$ as follows: | Test point ID | $T=$ | $n=$ | | :------: | :----: | :----: | | 1 | $100$ | $2$ | | 2 | $100$ | $2$ | | 3 | $100$ | $3$ | | 4 | $100$ | $3$ | | 5 | $100$ | $4$ | | 6 | $100$ | $4$ | | 7 | $100$ | $10$ | | 8 | $100$ | $11$ | | 9 | $100$ | $12$ | | 10 | $100$ | $13$ | | 11 | $100$ | $14$ | | 12 | $100$ | $15$ | | 13 | $10$ | $16$ | | 14 | $10$ | $17$ | | 15 | $10$ | $18$ | | 16 | $10$ | $19$ | | 17 | $10$ | $20$ | | 18 | $10$ | $21$ | | 19 | $10$ | $22$ | | 20 | $10$ | $23$ | It is guaranteed that all hands are randomly generated. Translated by ChatGPT 5