公式

E - Expansion Packs 解説 by en_translator


Let \(f_i\) be the expected number of packs to unpack until you need to get \(i\) more rare cards, and \(g_i\) be the probability that a pack contains exactly \(i\) rare cards. The sought value is \(f_X\).

We evaluate \(f_i\) in the manner of DP (Dynamic Programming). For \(i = 0\), we have \(f_i = 0\). For \(i > 0\), considering the number of rare cards contained in the next pack to open, we can derive \(f_i = 1 + \displaystyle\sum_{j = 0}^{N} f_{ \max(i - j, 0) }g_j\). On its own the right hand side contains a term containing \(f_i\), so a naive DP is impossible, but transposing the \(j = 0\) term yields \(f_i(1 - g_0) =\displaystyle\sum_{j = 1}^{N} f_{ \max(i - j, 0) }g_j\), thus \(f_i =\frac{1}{1 - g_0}\displaystyle\sum_{j = 1}^{N} f_{ \max(i - j, 0) }g_j\), which enables us to find \(f_i\) in ascending order of \(f_i\). Note that \(1 - g_0 \neq 0\), because the constraints guarantee \(g_0 \leq \frac{99}{100}\).

Therefore, when we know the values \(g_j\), we can compute \(f_X\) in a total of \(O(NX)\) time.

Now it has been boiled down to finding \(g_j\); these can also be evaluated in the manner of DP. Let \(dp_ { i, j }\) be the probability that there are exactly \(j\) cards among the \(1\)-st, \(2\)-nd, \(\ldots\), and \(i\)-th cards. By summing up the two cases where the \(i\)-th card is and is not a rare card, we arrive at \(dp_{ i,j } = \frac{ P_i }{100} dp_{ i - 1, j - 1 } + (1 - \frac{ P_i }{100})dp_ { i - 1, j }\). This DP runs in a total of \(O(N ^ 2)\) time, and \(g_j = dp_{ N, j }\).

Therefore, the problem can be solved in a total of \(O(NX + N ^ 2)\) time.

投稿日時:
最終更新: