Real-Programmer-Game
一道dp/概率论的题目。
source:北美字节(Tik ToK)的题难到逆天了 - V2EX
description
Real Programmer Game (RPG) is about having a hero swinging sticks at a monster.
The monster has N Health Points (НР). It is killed when HP drops to 0 or negative.
Each swing of the hero reduces monster’s HP by a (evenly distributed) random number in
[0, M].
What’s the probability for the hero to kill the monster in K swings?
Write a function, input N, M, K, return such probability (in [0, 1]).
Constraints
0<=N<= 1000
0<M <= 1000
0<=K<= 1000
题目意思就是求$X_i\sim U(0,M),P(\sum_{i=1}^{K} X_i\ge N)$。
Solution
$X_i$ 只能取整数
dp。
时间复杂度为 $O(M^2K^3)$,可以用前缀和优化到 $O(MK^2)$,空间复杂度使用滚动数组为 $O(MK)$。
1 | const int MAXN = 1050, MAXM = 1050, MAXK = 1050; |
似乎超时了?
取有理数
秒变数学题。。
当 $N=1$ 时累计分布函数为
欧文–贺尔分布 - 维基百科,自由的百科全书 (wikipedia.org)
建议mathematica解题。UniformSumDistribution—Wolfram 语言参考资料