Topcoder SRM 488 DIV1 250 (probabilistic DP)

Source: Internet
Author: User

Test instructions: There are n chat people and M boring people, each time the probability of choice of two people, let them become bored people, ask everyone to become bored people's expectations. ( < Span class= "Mrow" id= "mathjax-span-2" > 1 ≤ n m ≤ )。

Solution: Set F (i) indicates the number of expected times that I have a chat person and turn everyone into boring people. Obviously f (0) = 0, i.e. no change is required. Equation: F (I)=F (I?2)x C 2 i C 2 N+m +F (I?1)xi x ( n + m ? i ) C 2 N+m +F (I)x C 2 N+m? I C 2 N+m +1 .
The answer is f (m)

Code

#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>classtheboredomdivone{ Public:Doublef[ -];DoubleCDoublex) {returnX * (X-1) /2; }DoubleFindintNintm) {memset(F,0,sizeof(f)); f[0] =0; for(inti =1; I <= m; i++) {F[i] = (f[i-2] * C (i) + f[i-1] * I * (n + m-i) + C (n + M))/(c (n + M)-C (n + m-i)); }returnF[M]; }};

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Topcoder SRM 488 DIV1 250 (probabilistic DP)

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.