Bin & Jing in Wonderland (probability, combinatorial math)

Source: Internet
Author: User
Tags float number

problem 2103 Bin & Jing in Wonderlandaccept:201 submit:1048 time limit:1000 mSec Memory limit:32768 KBproblem Description

Bin has a dream that he and Jing is both in a wonderland full of beautiful gifts. Bin wants to choose some gifts for Jing to get in her good graces.

There is N different gifts in the Wonderland, with an ID from 1 to N, and all kinds of these gifts has infinite duplicates. Each time, Bin shouts loudly, ' I love Jing ', and then the Wonderland random drop a gift in front of bin. The dropping probability for gift I (1≤i≤n) is P (i). of cause, P (1) +p (2) +...+p (N) =1. Bin finds the gifts with the higher ID is better. Bin shouts K times and selects R best gifts finally.

That's, firstly Bin gets k gifts, then sorts all these gifts according to their ID, and picks up the largest R gifts at l Ast. Now, if given the final list of the R largest gifts, can do help Bin find out the the probability of the list?

Input

The first line of the input contains an integer T (t≤2,000), indicating number of test cases.

For each test cast, the first line contains 3 integers N, K and R (1≤n≤20, 1≤k≤52, 1≤r≤min (k,25)) as the description above . In the second line, there is N positive float numbers indicates the probability of each gift. There is at most 3 digits after the decimal point. The third line has an r integers ranging from 1 to N indicates the finally list of the "R Best Gifts ' ID.

OutputFor each case, output a float number with 6 digits after the decimal points, which indicates the probability of the final List.Sample Input4 2 3 3 0.3 0.7 1 1 1 2 3 3 0.3 0.7 1 1 2 2 3 3 0.3 0.7 1 2 2 2 3 3 0.3 0.7 2 2 2Sample Output0.027000 0.189000 0.441000 0.343000Source"Higher Education Society Cup" the third Fujian University College Students Program Design contest: There are n kinds of apples, a person in the following shout K times, each fall down an apple, each kind of apple fell the probability known, now give the former r Big Apple species; Ask the probability of the smallest occurrence, find out the probability of a large ratio of MI, To find out the probability of a smaller than MI, enumerate the number of MI occurrences, the probability of the need to multiply the good; code:
#include <iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<cstring>using namespacestd;Doublep[ -], dp[ -];typedefLong LongLL; LL c[ -][ -];intnum[ the];inta[ the];voiddb () {c[1][0] = c[1][1] =1;  for(inti =2; I < -; i++) {c[i][0] = C[i][i] =1;  for(intj =1; J < I; J + +) {C[i][j]= C[i-1][J] + c[i-1][j-1]; }    }}intMain () {intT, N, K, R; scanf ("%d", &T);    DB ();  while(t--) {scanf ("%d%d%d", &n, &k, &R); dp[0] =0;  for(inti =1; I <= N; i++) {scanf ("%LF", p +i); Dp[i]= Dp[i-1] +P[i]; }        DoubleAns =1; memset (num,0,sizeof(num)); intMi =0x3f3f3f3f;  for(inti =1; I <= R; i++) {scanf ("%d", A +i); Num[a[i]]++; Mi=min (mi, a[i]); }        intnow =K;  for(inti = mi +1; I <= N; i++){            if(!num[i])Continue; Ans*= C[now][num[i]] *Pow (p[i], num[i]); now-=Num[i]; }        DoubleANS1 =0;  for(inti = Num[mi]; I <= k-r + num[mi]; i++) {ans1+ = C[k-r + num[mi]][i] * POW (p[mi], i) * POW (DP[MI-1], K-r + Num[mi]-i); } printf ("%.6lf\n", ans *ans1); }    return 0;}

Bin & Jing in Wonderland (probability, combinatorial math)

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.