Lightoj 1342 Aladdin and the magical sticks [idea title]

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.