Question Link
Question: I threw a dice on the m Plane n times and expected the maximum value.
Idea: mathematical expectation. The formula for discretization is E (x) = x1 * P (X1) + x2 * P (X2) + ...... + Xn * P (Xn)
P (xi) indicates the number of all cases where the maximum value is XI/The total number of cases is m ^ N, throwing n times, the number of all cases where the maximum value is XI should be Xi ^ N, but the maximum value is not XI and cannot exceed Xi, so subtract the maximum value is a XI-1 or the maximum value does not exceed this number of cases. That is, sum + = xi * (Xi ^ N-(XI-1) ^ N)/m ^ N, but this is certainly not good, because the value range of M n is 10 ^ 5, 100000 ^ 100000 will overflow and the M ^ N in this formula will be mentioned in brackets, that is, sum + = xi * (XI/m) ^ N-(XI-1)/m) ^ N ).
1 //C. Little Pony and Expected Maximum 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <cmath> 6 7 using namespace std ; 8 9 int main()10 {11 double m , n ;12 while(~scanf("%lf %lf",&m,&n))13 {14 double sum = 0.0;15 for(int i = 1 ; i <= m ; i++)16 {17 sum += (pow(i/m,n)-pow((i-1)/m,n))*i ;18 }19 printf("%.12lf\n",sum) ;20 }21 return 0 ;22 }View code