Official

E - Throwing the Die Editorial by en_translator


When continuing the game, the result so far does not affect the score, so the expected value depends only on how many extra times we can roll the die.

Let \(f(N)\) be the maximum expected score if we can roll a die \(N\) more times. When the die shows \(D\), we can gain a score \(D\) if we quit the game, or \(f(N-1)\) if we continue, where we can choose the larger, so we have

\(f(N)=\frac{1}{6}\max(1,f(N-1))+\frac{1}{6}\max(2,f(N-1))+\frac{1}{6}\max(3,f(N-1))+\frac{1}{6}\max(4,f(N-1))+\frac{1}{6}\max(5,f(N-1))+\frac{1}{6}\max(6,f(N-1)).\)

Therefore, we can calculate it in ascending order of \(N\).

Sample code (C)

posted:
last update: