公式

F - Make 10 Again 解説 by en_translator


Let us simply say an integer \(k\) is obtainable when we can choose the cast dice so that the results sums up to \(k\).

We solve this problem with a dynamic programming (so-called bit DP). Instead of casting \(N\) dice, we consider casting dice one-by-one from the first one in order, and the set of integers obtainable after casting each die. In this problem, we are only interested in whether we can obtain the sum of \(10\) or not, so the integers greater than \(10\) can be ignored. So let us define the DP table by

\(\mathrm{dp}[i][S] = \) ( the probability that the set of obtainable integers is \(S\) when the first \(i\) dice are cast).

By filling this DP table, the answer can be obtained as

\[\sum_{S \owns 10} \mathrm{dp}[N][S].\]

We first consider the initialization of the DP. At first, \(0\) dice have been cast, and only \(0\) is obtainable (by choosing zero results from the zero cast dies), so

\[ \mathrm{dp}[0][S] = \begin{cases} 1 &\,\,\text{if}\,\, S = \lbrace 0 \rbrace \\ 0 &\,\,\text{if}\,\, S \neq \lbrace 0 \rbrace. \end{cases} \]

Next, we consider the transitions of the DP. Assume that we have cast the first \(i\) dice, and the set of obtainable integers no more than \(10\) is \(S\). If the \((i+1)\)-th die shows \(x\), the \(10\)-or-less integers obtained by the first \((i+1)\) results (including this one) is the union \(S \cup T_x\) of

  • the set of obtainable integers where the new result \(x\) is not chosen (which coincides with the set of integers \(S\) obtainable from the first \(i\) results), and
  • the set of obtainable integers where the new result \(x\) is chosen (which coincides with \(T_x \coloneqq \lbrace s + x : s \in S \rbrace \cap \{0, 1, 2, \ldots, 10\}\), because we can obtain \(s+x\), where \(s \in S\) is an integer originally obtainable from the first \(i\) results).

The \((i+1)\)-th die results in one of \(1, 2, \ldots, A_{i+1}\) with a equal probability of \(1 / A_{i+1}\), so if \(A_{i+1} \leq 10\), we perform the following \(A_{i+1}\) transitions:

  • add \(\mathrm{dp}[i][S] \times (1 / A_{i+1})\) to \(\mathrm{dp}[i+1][S \cup T_1]\) to consider \(x = 1\) case;
  • add \(\mathrm{dp}[i][S] \times (1 / A_{i+1})\) to \(\mathrm{dp}[i+1][S \cup T_2]\) to consider \(x = 2\) case;
  • \(\cdots\)
  • add \(\mathrm{dp}[i][S] \times (1 / A_{i+1})\) to \(\mathrm{dp}[i+1][S \cup T_{A_{i+1}}]\) to consider \(x = A_{i+1}\) case.

If \(A_{i+1} \gt 10\), the transitions for \(x \gt 10\) cases can be handled at once, because \(T_x = \emptyset\) for \(x \gt 10\). Specifically, we perform the following \(11\) transitions:

  • add \(\mathrm{dp}[i][S] \times (1 / A_{i+1})\) to \(\mathrm{dp}[i+1][S \cup T_1]\) to consider \(x = 1\) case;
  • add \(\mathrm{dp}[i][S] \times (1 / A_{i+1})\) to \(\mathrm{dp}[i+1][S \cup T_2]\) to consider \(x = 2\) case;
  • \(\cdots\)
  • add \(\mathrm{dp}[i][S] \times (1 / A_{i+1})\) to \(\mathrm{dp}[i+1][S \cup T_{10}]\) to consider \(x = 10\) case; and
  • add \(\mathrm{dp}[i][S] \times ((A_{i+1}-10) / A_{i+1})\) to \(\mathrm{dp}[i+1][S]\) to consider \(11 \leq x \leq A_{i+1}\) cases.

Since \(S \subseteq \lbrace 0, 1, 2, \ldots, 10 \rbrace\), there are at most \(2^{11} = 2048\) possible sets for \(S\), so the DP table has \(2048N \leq 204800\) states. Since at most \(11\) transitions are needed for each state, one can obtain the result fast enough by filling the DP table.

投稿日時:
最終更新: