Title Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27050
------------------------------------------------------------------------------------------------------------
Let's think about this first.
There is a pile of cards in which $n$ cards are drawn to the back of the other $m$ cards and put back
The expectation that each card will draw at least one required number of draw times
For this problem we can obviously list the desired equation after conversion to $dp$ equation to solve the complexity $o (NM) $
------------------------------------------------------------------------------------------------------------
Yet this complexity is not excellent enough
Then we need to take into account that if all is put back the complexity of only $o (n + M) $ $ ($ can also be solved with $dp$ $) $
If we think of what we don't put back, then once we get it back, $ ($ for the first time) is not counted this time.
So you don't put it back, only the last minus the contribution.
------------------------------------------------------------------------------------------------------------
Since the expectation of the cards that are not put back is the expectation of the cards put back by the $1$ is also a fixed value
So it's easy to add weights.
Since the value calculated by $dp$ is exactly the $γ$ of the Euler constant, the former $n$ subparagraphs
So just preprocess it for each $n$ $γ$.
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5 using namespacestd;6 Const intN =5010;7 DoubleR[n];8 intt, N;9 Doubleans;Ten intMain () One { A for(inti =1; I <= the; ++i) -R[i] = r[i-1] +1.0/i; -scanf"%d", &t); the for(intCA =1; CA <= T; ++CA) - { - intx, y; -scanf"%d", &n); +Ans =0; - for(inti =1; I <= N; ++i) + { Ascanf"%d%d", &x, &y); at if(Y = =1) -Ans + =x; - Else -Ans + = r[n] *x; - } -printf"Case %d:%.7f\n", CA, ans); in } - return 0; to}
Lightoj 1342 Aladdin and the magical sticks [idea title]