Probability method
Demands out and expectations, the basic theorem of expectation, and the expectation of each part of the desired and.
E (sum) = e (1) + E (2) + ... + e (x);
The probability P =1-(1-1/x) ^b, which is selected in B-time, is only selected and not selected in each of the numbers in B.
So the expectation of each number is also i* (1-1/x) ^b)
Get the sum expectation.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;d ouble e[110000];d ouble F (Double X,int d) { double ans = 1.0; if (d = = 0) return 1.0; ans = f (x,d/2); Ans *= ans; if (d%2) ans *= x; return ans;} int main () { int t, TT, X, D, I; scanf ("%d", &t); for (TT = 1; TT <= t; tt++) { scanf ("%d%d", &x, &d); for (i = 1; i <= x; i++) e[i] = 1.0-f (1.0-1.0/x,d); for (e[0] = 0, i = 1; i <= x; i++) e[0] + = e[i]*i; printf ("Case #%d:%.3lf\n", TT, E[0]); } return 0;}
Combination method
And all the results may appear and divide by the total kind.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;d ouble c[10]; int a[10][ int main () {int T, TT, X, B, N, I, J; Double ans, k; A[0][0] = 1; for (i = 1; I <= 5; i++) {a[i][1] = 1; A[i][i] = a[i-1][i-1] * i; } a[3][2] = 6; A[4][2] = 14; A[4][3] = 36; A[5][2] = 30; A[5][3] = 150; A[5][4] = 240; scanf ("%d", &t); for (TT = 1; TT <= t; tt++) {ans = 0; scanf ("%d%d", &x, &b); n = min (x,b); C[0] = 1; for (i = 1; I <= n-1; i++) {for (j = 1, k = 1; J <= I; j + +) {k *= ( (x-1)-j+1) *1.0/j; } if (I >= 2) c[i] = k/(x*1.0*x); else c[i] = k; } for (i = 1; I <= n; i++) {//printf ("C--%lf%lf\n", C[i-1], ((x+1) *1.0*x/2.0) * A[b][i]) ; K = c[i-1] * 1.0 * (x+1) *1.0*x/2.0) * A[b][i]; printf ("%lf\n", K); int m = b; if (I >= 3) m = b-2; for (j = 1; j <= M; j + +) K/= (x*1.0); printf ("%lf\n", K); Ans + = k; } printf ("Case #%d:%.3lf\n", tt, ANS); } return 0;}
Hdu5159--bc--card (probability notation, and combinatorial notation)