Tco09 Round 1 kthprobableelement (DP or probability statistics)

Source: Internet
Author: User

 

Question link: http://www.topcoder.com/stat? C = problem_statement & PM = 10335.

General meaning of the question:

Take the number of m in the middle of the interval [lower, upper] so that the number of K smaller values in the number of M is the probability of N.

Solution 1: (powerful DP) written by referring to others' problem-solving reports

DP [m] [s] [B]
Take the number of M, the maximum number of s smaller than N, the probability of a maximum of B larger than N (note the maximum number of 2 words)

DP [0] [s] [B] = 1
This Initialization is very important.

DP [m] [s] [B] = Pe * DP [M-1] [s] [B] +
PS * DP [M-1] [s-1] [B] + Pb * DP [s-1] [s] [b-1] (of course, ensure that s-1 and B-1 are greater than 0 before conversion)

Totel = upper-lower + 1;

PE is the probability that PE is equal to n = 1/totel;

PS is a probability smaller than N. PS = (n-lower)/totel;

PB is the probability Pb = (upper-N)/totel;

# Include <iostream> <br/> using namespace STD; <br/> class kthprobableelement <br/>{< br/> public: <br/> double DP [101] [101] [101]; <br/> double probability (int m, int lowerbound, int upperbound, int N, int K) <br/> {<br/> double Pe = 1.0/(upperbound-lowerbound + 1); <br/> double PS = (double) (N-lowerbound) /(upperbound-lowerbound + 1); <br/> double Pb = (double) (upperbound-N)/(upperbound-lowerbound + 1 ); <br/> for (INT m = 0; m <= m; m ++) <br/> {<br/> for (int s = 0; S <= K-1; s ++) <br/> {<br/> for (INT B = 0; B <= M-K; B ++) <br/> {<br/> If (M = 0) <br/> DP [m] [s] [B] = 1; <br/> else <br/> {<br/> DP [m] [s] [B] = Pe * DP M-1] [s] [B]; <br/> If (S> 0) <br/> DP [m] [s] [B] + = Ps * DP [s-1] [s-1] [B]; <br/> If (B> 0) <br/> DP [m] [s] [B] + = Pb * DP [s-1] [s] [b-1]; <br/>}< br/> return DP [m] [K-1] [M-K]; <br/>}< br/>}; <br/> 

Solution 2: Probability Analysis Statistics

The number of K is N. Suppose there is a number smaller than N, and there is B number larger than N, then M-A-B is equal to n.

Just ensure a <= K-1
B <= m-K, then the number of K is n

Then the probability of A and B for each decision is:

C (m, a) * pA ^ A * C (m-a, B) * pb ^ B * PAB ^ (m-a-B) Pa, Pb, pab is similar to the above ps, PB

Finally, enumerate a and B that meet the conditions to accumulate the probability.

 

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.