Picking Up the Dice
Time limit1sMemory limit1024 MB
Given K dice and a first roll, find the smallest number of dice to re-roll that maximizes the chance of reaching the target total T.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Probability, Combinatorics
- Solved
- No attempts yet
Statement
Two players play a game with a set of six-sided dice. One player calls out a number in the range , and the other player tries to roll that number. After the first roll, the player may pick up any number of dice () and roll them again.
Given the number of dice, the target number, and the numbers the player rolled the first time, how many dice should the player pick up to maximize the chance of getting the target number on the second roll?
Input
The first line contains two integers, , the number of dice, and , the target number. , .
The next line contains integers, the numbers shown on each die in the first roll. Every value is an integer from to .
Output
Print a single integer, the number of dice the player should pick up and roll again to maximize the chance of getting a total of . The player chooses which dice to pick up, but the output asks only for the count.
If more than one count gives the same maximum probability, print the smallest one.