Casino
Time limit8sMemory limit512 MB
Roll N dice up to M times, stopping whenever you like, and find the expected score under the optimal stopping strategy.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Probability, Math, Binary search
- Solved
- No attempts yet
Problem
The company you work for is developing a new casino game. Today you have decided to examine a game that was recently proposed.
In this game, you roll dice at the same time, and the sum of the rolled faces is your score. The player aims to make the score as large as possible. If you do not like the faces you rolled, you can reroll the dice, but in that case you must reroll all dice at the same time. You may roll the dice at most times. If you think the faces you rolled are large enough, you may end the game in fewer than rolls, and the sum of the faces from the last roll becomes your score.
To set an appropriate wager, you must find the expected value of the score. Given and , your task today is to find the expected score when using an optimal strategy.
The dice used in this game have faces numbered 1 through 6, and each face is equally likely to appear.
Input
The input consists of at most 100 datasets. Each dataset is given in the following format.
N M
The integers and satisfy and .
The end of the input is indicated by a line containing two zeros.
Output
For each dataset, print the expected value under an optimal strategy on a single line. The output must not have an absolute error greater than . Solutions for this problem are expected to accumulate large numerical errors, so using a high-precision type is recommended.