#P2668. [NOIP 2015 提高组] 斗地主

    ID: 1692 远端评测题 2000ms 1000MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>搜索贪心2015NOIp 提高组深度优先搜索,DFS

[NOIP 2015 提高组] 斗地主

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 AA to KK, plus the two jokers, for a total of 5454 cards. In Dou Dizhu, the rank order of the cards is represented by their face values as follows: $3<4<5<6<7<8<9<10<J<Q<K<A<2<\text{small Joker}<\text{big Joker}$, and suits do not affect the rank. In each round, a hand consists of nn cards. Each turn, a player may play according to the allowed patterns. The first player to play all of their cards wins the game.

Now, Niuniu only wants to know, for several sets of hands, the minimum number of plays required to play out each of them. Please help him solve this problem.

Note that in this problem, the playable patterns per turn are similar to those in standard Dou Dizhu but slightly different. The specific rules are as follows:

The testdata for this problem is random and hacks are not supported. To hack or use stronger testdata please click here.

Input Format

The first line contains two positive integers T,nT, n separated by a space, representing the number of hand sets and the number of cards in each hand.

Then follow TT groups of data. Each group contains nn lines, each line containing a pair of nonnegative integers ai,bia_i, b_i representing a card, where aia_i is the rank and bib_i is the suit, separated by a space. Specifically, we use 11 to represent rank AA, 1111 to represent rank JJ, 1212 to represent rank QQ, and 1313 to represent rank KK; spades, hearts, clubs, and diamonds are represented by 1144, respectively; the small joker is represented by 0 1, and the big joker is represented by 0 2.

Output Format

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

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 set with 88 cards: diamond 77, diamond 88, spade 99, diamond 1010, spade JJ, spade 55, diamond AA, and spade AA. You can finish in 33 plays by playing a straight of singles (diamond 77, diamond 88, spade 99, diamond 1010, spade JJ), a single (spade 55), and a pair (spade AA and diamond AA).

For different test points, we define the scales of the number of hand sets TT and the number of cards nn as follows:

Test point ID T=T= n=n=
1 100100 22
2
3 33
4
5 44
6
7 1010
8 1111
9 1212
10 1313
11 1414
12 1515
13 1010 1616
14 1717
15 1818
16 1919
17 2020
18 2121
19 2222
20 2323

It is guaranteed that all hands are randomly generated.

Translated by ChatGPT 5