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 were N people trying to the throw balls into M identical baskets. At the turn we all were selecting a basket and trying to throw a ball into it. After the game we saw exactly S balls were successful. Now you'll be given the value of N and M. For each player probability of throwing a ball to any basket successfully is P. Assume, there is infinitely many BA LLS and the probability of choosing a basket by any player is 1/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 after K turns.
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 numb Er 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
Output for Sample Input
2
1 1 1 0.5
1 1 2 0.5
Case 1:0.5
Case 2:1
Problem Setter:muhammad Rifayat Samee
Special Thanks:jane Alam Jan
First of all we need to know every time the throw, 0 people throw in the probability of 1 people throw into the probability of ....
Because I don't care about the specifics of the ball in the M basket, M is actually useless.
As long as the distinction is not thrown in, as to which basket to throw whatever
DP[I][J] Indicates the probability of a J-ball in the basket in the first round.
The final answer is ΣI?d P[k][I]
/************************************************************************* > File name:l.cpp > Author:al ex > Mail: [email protected] > Created time:2015 May 17 Sunday 16:05 37 seconds ************************************** **********************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;Doubledp[ the][1700];//ith turns, p of J BallsDoublepa[ -];intc[ -][ -];voidInit () {c[0][0] =1; for(inti =1; I <= -; ++i) {c[i][0] =1; c[i][1] = i; for(intj =2; J < I; ++J) {C[i][j] = c[i-1][J] + c[i-1][j-1]; } C[i][i] =1; }}DoublePow (DoubleAintb) {DoubleAns =1; for(inti =1; I <= b; ++i) {ans *= A; }returnAns;}intMain () {init ();intTintIcase =1;scanf("%d", &t); while(t--) {intN, M, K;DoublePscanf("%D%D%D%LF", &n, &m, &k, &p);memset(DP,0,sizeof(DP)); dp[0][0] =1; for(inti =0; I <= N; ++i) {Pa[i] = c[n][i] * POW (P, i) * POW ((1-p), n-i); } for(inti =1; I <= K; ++i) { for(intj =0; J <= (I-1) * N; ++J) { for(intL =0; L <= N; ++L) {if(j + L <= I * N) {dp[i][j + L] + = dp[i-1][J] * Pa[l]; } } } }DoubleE =0; for(inti =0; I <= k * n; ++i) {E + = dp[k][i] * i; }printf("Case%d:%.12f\n", icase++, E); }return 0;}
LightOJ1317---Throwing Balls into the baskets (probability DP)