N individual m baskets each round each one can choose M basket in the probability of throwing a ball in the throw is p to find the number of balls in all baskets after the K-wheel value
The expected number of balls based on the full expectation formula is dp[1]*1+dp[2]*2+...+dp[n]*n as W
Where Dp[i] is the probability of a person throwing in dp[i] = C (n, i) *p^i* (1-p) ^ (n-i) The final answer is W*k
#include <cstdio> #include <cstring>using namespace std;double dp[20];d ouble a[20], b[20];d ouble cm (int n, int m) {Double ans = 1;for (int i = 1; I <= m; i++) {ans *= (double) N--;ans/= (double) I;} return ans;} int main () {int t;int cas = 1;scanf ("%d", &t), while (t--) {int n, m, k;double p;scanf ("%d%d%d%lf", &n, &m, &am P;k, &p);DP [0] = a[0] = b[0] = 1;for (int i = 1; I <= n; i++) {a[i] = a[i-1]*p;b[i] = b[i-1]* (1-p);} for (int i = 0; I <= N; i++) {Dp[i] = cm (n, i) *a[i]*b[n-i];} Double ans = 0;for (int i = 1; I <= n; i++) ans + dp[i]* (double) I;ans *= (double) k;printf ("Case%d:%.10lf\n", cas++, an s);} return 0;}
Light OJ 1317 throwing Balls into the baskets probability DP