#P2540. [NOIP 2015 提高组] 斗地主 加强版
[NOIP 2015 提高组] 斗地主 加强版
Description
Niuniu has recently become obsessed with a card game called Dou Dizhu. Dou Dizhu is a poker game played with a deck of cards: through in Spades, Hearts, Clubs, and Diamonds, plus the two Jokers. In Dou Dizhu, the card ranks are ordered by their numbers as follows: , and suits do not affect card strength. In each game, a hand consists of cards. Each turn, a player may play cards according to certain allowed patterns. The side that first plays out all cards wins.
Now, Niuniu only wants to know, for several of his hands, the minimum number of plays needed to play out all the cards in each hand. Please help him solve this problem.
Note that in this problem, the set of playable patterns per move is similar to standard Dou Dizhu but slightly different. The specific rules are as follows:

In this problem, the two Jokers cannot form a pair.
Input Format
The first line contains positive integers separated by a space, representing the number of hands and the number of cards in each hand.
Then follow groups of data. For each group, there are lines, each containing a pair of non-negative integers , representing one card, where is the card rank and is the suit, separated by a space. Specifically, we use to represent rank , for , for , and for ; Spades, Hearts, Clubs, and Diamonds are represented by – respectively; the small Joker is represented as 0 1, and the big Joker as 0 2.
Output Format
Output lines. Each line contains one integer, the minimum number of plays needed to play out the -th hand.
1 8
7 4
8 4
9 1
10 4
11 1
5 1
1 4
1 1
3
1 17
12 3
4 3
2 3
5 4
10 2
3 3
12 2
0 1
1 3
10 1
6 2
12 1
11 3
5 2
12 4
2 2
7 2
6
Hint
Sample 1 Explanation
There is hand containing cards: Diamonds , Diamonds , Spades , Diamonds , Spades , Spades , Diamonds , and Spades . You can play them out in moves by playing a single straight (Diamonds , Diamonds , Spades , Diamonds , Spades ), a single card (Spades ), and a pair (Spades and Diamonds ).
Constraints and Notes
For the first test points, the scales of the number of hands and the number of cards are as follows:

The testdata does not guarantee that all hands are randomly generated.
Translated by ChatGPT 5
京公网安备 11011102002149号