#abc224g. G - Roll or Increment
G - Roll or Increment
Score : points
问题描述
我们有一个 面骰子,每个面分别显示从 到 的整数,并且出现每个整数的概率相等。
当骰子顶部朝上的面显示整数 时,我们称骰子当前显示的值为 。
最初,骰子显示的整数为 。
你可以对这个骰子进行以下两种操作任意次(包括零次),并且可以按任意顺序执行:
- 支付 日元(日本货币)以“增加”骰子上显示的数值,即当骰子当前显示 时,重新放置它使其显示 。但当骰子显示 时,不能进行此操作。
- 支付 日元来重掷骰子,之后骰子将以相等的概率显示 到 之间的某个整数。
从初始状态下骰子显示 开始,考虑使其最终显示 。
请计算并输出在采用最优策略以最小化期望成本时,完成这一目标所需的最小期望成本。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a -face die (singular of dice) that shows integers from through with equal probability.
Below, the die is said to be showing an integer when it is placed so that the top face is the face with the integer .
Initially, the die shows the integer .
You can do the following two operations on this die any number (possibly zero) of times in any order.
- Pay yen (the Japanese currency) to "increase" the value shown by the die by , that is, reposition it to show when it currently shows . This operation cannot be done when the die shows .
- Pay yen to recast the die, after which it will show an integer between and with equal probability.
Consider making the die show from the initial state where it shows .
Print the minimum expected value of the cost required to do so when the optimal strategy is used to minimize this expected value.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer. Your output will be considered correct when its absolute or relative error is at most .
Sample Input 1
5 2 4 10 4
Sample Output 1
15.0000000000000000
When the optimal strategy is used to minimize the expected cost, it will be yen.
Sample Input 2
10 6 6 1 2
Sample Output 2
0.0000000000000000
The die already shows in the initial state, which means no operation is needed.
Sample Input 3
1000000000 1000000000 1 1000000000 1000000000
Sample Output 3
1000000000000000000.0000000000000000
Your output will be considered correct when its absolute or relative error is at most .
update @ 2024/3/10 09:52:18