[Hidden ☆ before use]
#### 1217. H. Rummy Score

#### Description

Mack and Zack (Dr. Orooji’s twins) play Rummy with a modified deck of playing cards. The

card values are 1 through 13 (1 does not serve the dual purpose of 1 and 14; it is only 1) and

there are no suits. Also, a deck may contain any number of each card value (unlike a standard

deck of cards which has exactly four of each).

The Problem:

Given the seven cards in a Rummy hand (held by Mack or Zack), you are to determine the points

lost by the hand. In Rummy, you group three (or more) cards together if they have the same

value or they have consecutive values. Examples of a group include {4, 4, 4}, {6, 6, 6, 6, 6},

{9, 10, 11}, and {1, 2, 3, 4}. The “points lost by a hand” is the sum of values for cards that are

not in a group.

When computing the points lost by a hand, you group the cards to minimize the loss, i.e., you

want the smallest total sum of values for the ungrouped cards. Note that a given card could

possibly belong to more than one group; you need to pick the group that minimizes the total

points lost. For example, given the seven cards {2, 2, 2, 3, 4, 8, 10}, the grouping {2, 3, 4} is

better than the grouping {2, 2, 2}. Note also that a card can be used in only one group, e.g., from

the Rummy hand {2, 2, 2, 3, 4, 8, 10}, we can not create the two groups {2, 2, 2} and {2, 3, 4}

since there are not a total of four cards with a value of 2 in the hand.

#### Input

The first input line contains only a positive integer, n, indicating the number of Rummy hands.

The hands are on the following n input lines, one set per line. Each set contains seven integers,

each integer between 1 and 13, inclusive (the values are separated by a single space).

#### Output

At the beginning of each test case, output “Rummy Hand: v” where v is the input values.

Then, on the next output line, print the points lost by the hand. Leave a blank line after the

output for each test case. Follow the format illustrated in Sample Output.

#### Samples

#### Source

UCF2012

card values are 1 through 13 (1 does not serve the dual purpose of 1 and 14; it is only 1) and

there are no suits. Also, a deck may contain any number of each card value (unlike a standard

deck of cards which has exactly four of each).

The Problem:

Given the seven cards in a Rummy hand (held by Mack or Zack), you are to determine the points

lost by the hand. In Rummy, you group three (or more) cards together if they have the same

value or they have consecutive values. Examples of a group include {4, 4, 4}, {6, 6, 6, 6, 6},

{9, 10, 11}, and {1, 2, 3, 4}. The “points lost by a hand” is the sum of values for cards that are

not in a group.

When computing the points lost by a hand, you group the cards to minimize the loss, i.e., you

want the smallest total sum of values for the ungrouped cards. Note that a given card could

possibly belong to more than one group; you need to pick the group that minimizes the total

points lost. For example, given the seven cards {2, 2, 2, 3, 4, 8, 10}, the grouping {2, 3, 4} is

better than the grouping {2, 2, 2}. Note also that a card can be used in only one group, e.g., from

the Rummy hand {2, 2, 2, 3, 4, 8, 10}, we can not create the two groups {2, 2, 2} and {2, 3, 4}

since there are not a total of four cards with a value of 2 in the hand.

The hands are on the following n input lines, one set per line. Each set contains seven integers,

each integer between 1 and 13, inclusive (the values are separated by a single space).

Then, on the next output line, print the points lost by the hand. Leave a blank line after the

output for each test case. Follow the format illustrated in Sample Output.

Input
Copy

7 5 2 2 6 2 10 4 11 11 11 11 1 2 3 11 2 3 4 5 13 1 4 5 6 6 6 6 13 2 2 2 3 4 8 10 12 13 1 4 4 4 4 10 10 10 8 9 8 9

Output

Rummy Hand: 5 2 2 6 2 10 4 10 Rummy Hand: 11 11 11 11 1 2 3 0 Rummy Hand: 11 2 3 4 5 13 1 24 Rummy Hand: 4 5 6 6 6 6 13 13 Rummy Hand: 2 2 2 3 4 8 10 22 Rummy Hand: 12 13 1 4 4 4 4 26 Rummy Hand: 10 10 10 8 9 8 9 10

Time Limit: | 1000MS (C/C++,Others×2) |

Memory Limit: | 128MB (C/C++,Others×2) |

Special Judge: | No |

AC/Submit: | 1 / 1 |

Tags: |