Problem Statement
This problem is about dice. All dice in this problem are the standard six-sided dice with numbers 1 through 6 on their faces.
Consider the following game that is played with n dice:
- Your opponent chooses a positive integer target (between n and 6n, inclusive).
- You roll all n dice.
- You select any subset of the dice you rolled and you reroll them.
- You add the numbers that are now shown on the n dice. If the sum is exactly equal to target, you win, otherwise you lose.
This game is often played as a drinking game with one extra rule: for each die you rerolled in step 3 you have to drink a shot.
Monika is playing this game. Her priorities are as follows:
- She wants to have a chance to win the game.
- She wants to drink as few shots as possible.
You are given the
Definition
- Class:
- Reroll
- Method:
- minimumDice
- Parameters:
- int, int[]
- Returns:
- int
- Method signature:
- int minimumDice(int target, int[] dice)
- (be sure your method is public)
Constraints
- target will be between n and 6n, inclusive, where n is the number of elements in dice.
- dice will contain between 1 and 20 elements, inclusive.
- Each element of dice will be between 1 and 6, inclusive.
Examples
7
{2,6,4}
Returns: 1
The current sum is 12. In order to have a shot at having sum of 7, Monika has to reroll the 6 and hope for a 1.
10
{4,2,4,5}
Returns: 2
The current sum is 15. Monika can choose, for instance, to reroll the two fours. She will win if she gets a 1 and a 2.
42
{6,6,6,6,6,6,6}
Returns: 0
Monika has already won - no need to reroll anything.
42
{1,3,5,3,6,4,2}
Returns: 6
Out of all the dice, just the single 6 is useful. Monika has to reroll all other dice and hope they all land a six.
120
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
Returns: 20
20
{6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6}
Returns: 20
3
{1}
Returns: 1
2
{3}
Returns: 1
6
{5}
Returns: 1
2
{2}
Returns: 0
13
{6,5,4,5,3,3,1,6,5,4}
Returns: 8
21
{5,4,1,3,3,2,6,1,3,1,2,2,6,6,4,1,2,6,3,6}
Returns: 15
95
{5,3,2,3,4,1,4,6,6,5,5,4,4,6,5,4,5,1,1,4}
Returns: 4
49
{6,2,6,2,1,1,5,2,4,5,1,2,2,4,3,4,1,1,4,4}
Returns: 3
24
{1,3,2,4,6,3,6,3,1,3,6,4,3,2,4,4,2,6,2,3}
Returns: 14
34
{3,6,4,5,6,3,3,4,2,4,3,2,5,2,1,4,4,1,2,1}
Returns: 9
83
{6,1,3,4,2,1,4,3,5,2,1,4,2,3,3,2,4,5,1,3}
Returns: 5
51
{4,6,4,6,6,4,5,3,4,3,2,5,2,3,6,3,6,3,6,3}
Returns: 7
47
{1,4,3,5,2,3,1,2,5,3,6,3,2,5,5,3,3,6,2,6}
Returns: 5
58
{3,1,3,2,4,3,1,5,2,3,6,5,2,3,4,2,3,5,3,4}
Returns: 2
106
{3,4,2,4,3,2,3,5,5,3,4,1,3,6,2,2,6,4,3,1}
Returns: 11
34
{2,3,2,6,6,2,4,2,2,2,5,2,1,2,5,3,6,5,6,2}
Returns: 8
24
{3,2,6,6,5,2,2,1,4,4}
Returns: 3
44
{4,6,6,4,5,5,6,2,2,5}
Returns: 1
42
{4,3,4,3,6,6,2,4,4,1}
Returns: 1
28
{4,1,5,6,3,5,3,2,2,5}
Returns: 2
25
{6,3,6,5,4,5,5,3,5,3}
Returns: 5
43
{3,3,3,6,4,6,5,5,6,5}
Returns: 1
60
{2,1,2,6,5,5,2,6,4,3}
Returns: 8
43
{1,2,6,6,2,4,2,6,2,3}
Returns: 2
57
{5,2,1,5,4,1,3,1,2,1}
Returns: 8
25
{1,1,4,5,4}
Returns: 2
8
{3,5,6,2,3}
Returns: 3
14
{6,4,2,5,4}
Returns: 2
12
{6,3,3,4,2}
Returns: 2
30
{4,2,6,4,2}
Returns: 4
3
{3,2}
Returns: 1
5
{2,5}
Returns: 1
10
{4,3}
Returns: 1
12
{2,4}
Returns: 2
2
{1,2}
Returns: 1
2
{2,4}
Returns: 2
2
{5,3}
Returns: 2
9
{2,3}
Returns: 1
7
{1,4}
Returns: 1
2
{2,6}
Returns: 2
2
{1,5}
Returns: 1
12
{1,1}
Returns: 2
3
{4,5}
Returns: 2
78
{5,4,5,5,6,2,6,5,5,4,2,5,2,4,3,5,6,2,1}
Returns: 1
95
{4,6,2,2,6,4,3,6,5,2,6,1,1,3,5,5,5,5,4}
Returns: 5
67
{1,6,1,3,6,3,4,6,5,3,4,4,6,3,6,3,1,2}
Returns: 0
79
{2,3,1,3,6,5,4,5,1,2,6,5,5,5,1,5,3,6}
Returns: 3
68
{6,3,1,3,4,1,5,1,2,4,2,1,5,5,5,3,4}
Returns: 3
63
{4,2,3,1,4,5,2,4,5,6,4,4,5,2,2,3,5}
Returns: 1
82
{1,6,2,4,5,2,1,5,3,4,2,1,3,2,4,6}
Returns: 7
40
{2,1,6,3,4,5,5,4,4,4,5,3,6,3,4,5}
Returns: 6
24
{4,5,3,4,3,4,2,5,6,3,2,6,6,5,2}
Returns: 9
17
{1,6,1,4,4,1,4,2,3,3,3,2,3,3,2}
Returns: 10
42
{1, 3, 5, 3, 6, 4, 2 }
Returns: 6
10
{4, 2, 4, 5 }
Returns: 2
12
{1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }
Returns: 11
1
{6 }
Returns: 1
12
{1, 2, 3, 4 }
Returns: 1
7
{2, 6, 4 }
Returns: 1
10
{6, 6, 6, 6, 6, 6, 6 }
Returns: 7
32
{6, 6, 6, 6, 6, 6, 6, 1 }
Returns: 3
8
{2, 1, 6 }
Returns: 1