跳到正文

个人记录

Mar 27, 2021 Gym102798E So many possibilities

Wall_breaker约 4 分钟
原文
文章信息与版本

文章信息

发布
2021年3月28日
收录
2025年12月12日
更新
2026年11月18日
篇幅
约 4 分钟

版本

  1. v1当前

Mar 27, 2021 Gym102798E So many possibilities

The first time I saw this question, I mistakenly considered that the probability of each situation was equal. In fact, each step the operater makes may have different probability.

However, when I got to find my method was wrong, confusion sprang to my mind. How to solve it?

Consider using probability dynamic programing. Once we know who have died, we reach the number of operations. Actually, the order doesn’t affect the answer, because all the killed ones only add one more contribution.

Another strange thing to pay attention to is the range of “N”. 15?? We immediately come up with the state-compressed dynamic programing. So the key to the solution is clear now. But how to achieve the algorithm?

We define f[S][i]f[S][i] as using i steps to achieve S, each 1∈S1 \in S staying alive. Similarly, we define dp[S][i]dp[S][i], while all 1∈S1 \in S mean living ones and all 0∈S0 \in S mean killed ones. Sum[S]Sum[S] represents the summation of all the killed’s HPs and Cnt[S]Cnt[S] stands for the number of deaths.

If we finished i steps and intend to perform the next one, we will have two two different results :

(Attention : Must be aware of the meaning of "1(n−cnt[S])\frac{1}{(n - cnt[S])}"

I:I: We are not to kill anyone, then dp[S][i+1]+=dp[S][i]/(n−cnt[S])dp[S][i + 1]+=dp[S][i] / (n-cnt[S])

II:II: We killed a entourage kk, which means a[k]−1a[k] - 1 of the previous steps should be targeted on it. Ok, dp[S∣(1<<k−1)][i+1]+=dp[S][i]∗C(i−sum[S],a[k]−1)/(n−cnt[S])dp[S | (1 << k - 1)][i + 1] += dp[S][i] * C(i - sum[S], a[k] - 1) / (n - cnt[S])

So, Ans+=dp[S][i]∗f[S⊕((1<<n)−1)[i−sum[S]]∗cnt[S]Ans+=dp[S][i]*f[S \oplus ((1 << n) - 1)[i - sum[S]]*cnt[S]

The most essential and difficult part of all the process is to understand that the previous results have already caculated the steps made by the livings. We don’t need to do it twice.

原文