#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 5454 cards: AA through KK in Spades, Hearts, Clubs, and Diamonds, plus the two Jokers. In Dou Dizhu, the card ranks are ordered by their numbers as follows: 3<4<5<6<7<8<9<10<J<Q<K<A<2<小王<大王3<4<5<6<7<8<9<10<J<Q<K<A<2<\text{小王}<\text{大王}, and suits do not affect card strength. In each game, a hand consists of nn 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 22 positive integers T,nT, n separated by a space, representing the number of hands and the number of cards in each hand.

Then follow TT groups of data. For each group, there are nn lines, each containing a pair of non-negative integers ai,bia_i, b_i, representing one card, where aia_i is the card rank and bib_i is the suit, separated by a space. Specifically, we use 11 to represent rank AA, 1111 for JJ, 1212 for QQ, and 1313 for KK; Spades, Hearts, Clubs, and Diamonds are represented by 1144 respectively; the small Joker is represented as 0 1, and the big Joker as 0 2.

Output Format

Output TT lines. Each line contains one integer, the minimum number of plays needed to play out the ii-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 11 hand containing 88 cards: Diamonds 77, Diamonds 88, Spades 99, Diamonds 1010, Spades JJ, Spades 55, Diamonds AA, and Spades AA. You can play them out in 33 moves by playing a single straight (Diamonds 77, Diamonds 88, Spades 99, Diamonds 1010, Spades JJ), a single card (Spades 55), and a pair (Spades AA and Diamonds AA).

Constraints and Notes

For the first 2020 test points, the scales of the number of hands TT and the number of cards nn are as follows:

The testdata does not guarantee that all hands are randomly generated.

Translated by ChatGPT 5