Lightoj 1317 throwing Balls into the baskets (expected) Problem solving report
Title Link: Http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88890#problem/A
Topic:
Description
You probably has played the game "throwing Balls into the basket". It's a simple game. You had to throw a ball into a basket from a certain distance. One day we (the Aiub Acmmer) were playing the game. But it is slightly different from the main game. In our game we wereNPeople trying to throw balls intoMIdentical baskets. At the turn we all were selecting a basket and trying to throw a ball into it. After the game we saw exactlySBalls were successful. Now you'll be given the value ofNandM. For each player probability of throwing a ball to any basket successfully areP. Assume that there be infinitely many balls and the probability of choosing a basket by any player is1/m.If multiple people choose a common basket and throw their ball, you can assume that their balls would not conflict, and the Probability remains same for getting inside a basket. You have to find the expected number of balls entered into the baskets afterKTurns.
Input
Input starts with an integer T (≤100), denoting the number of test cases.
Each case starts with a line containing three integers N (1≤n≤16), M (1≤m≤100) and K (0≤k≤100) and a real number P (0 ≤ p ≤1). P contains at most three places after the decimal point.
Output
For each case, print the case number and the expected number of balls. Errors less than 10-6 'll be ignored.
Sample Input
2
1 1 1 0.5
1 1 2 0.5
Sample Output
Case 1:0.5
Case 2:1
Main topic:
There are n people, M baskets, a total dozen k round, each round each can cast a ball, each ball into the probability is P, after the K-wheel, the goal of the ball cast what is the expectation?
Analysis:
Because everyone throws in the same probability, so the expectation is the same. So just ask for the first round of expectations, and always expect to =k* the first round of expectations.
Code:
1#include <cstdio>2#include <iostream>3 using namespacestd;4 5 intt,n,m,k;6 DoubleP,ans;7 inta[ -][ -];8 9 voidInit ()Ten { Onea[1][1]=1; Aa[1][0]=1; - for(intI=2;i< -; i++) - { thea[i][i]=1; -a[i][0]=1; - for(intj=1; j<i;j++) -a[i][j]=a[i-1][j]+a[i-1][j-1]; + } - } + A DoubleCountintj) at { - Doubleb=1.0; - for(intI=0; i<j;i++) -B=b*p;//expectations in the cast - for(intI=0; i<n-j;i++) -b=b* (1.0-P);//no expectations in the cast in returnb*j*A[n][j]; - } to + intMain () - { the intC=1; *scanf"%d",&t); $ init ();Panax Notoginseng while(t--) - { thescanf"%D%D%D%LF",&n,&m,&k,&p); +ans=0.0;//decimal A for(intI=0; i<=n;i++) theAns+=count (i);//the first round of expectations +printf"Case %d:%.7lf\n", c++,ans*k); - } $ return 0; $}
Lightoj 1317 throwing Balls into the baskets