Test instructions: N-face Dice throw m times, to find the maximum value of expectations.
Other people's practice: probability of maximum i = probability of all points <=i-the probability of all points <=i-1, then directly calculated.
SB procedure: The accuracy requirement 1e-4, and M large when the maximum is a small number of probability is very small, the accuracy range does not affect the answer, so direct dp,f[i][j] means the probability of the maximum value of J after the throw I, through the prefix and optimization to do O (n) transfer
Equation is f[i][j]= (f[i-1][1]+f[i-1][2]+f[i-1][3]+....+f[i][j-1]) * (1/n) +f[i-1][j]* (j/n)
Because the smaller the number of points, the less the probability is not to consider the small items. Prevent WA so use the highest possible precision without time-outs.
#include <cstdio>#include<algorithm>using namespacestd;//#include <ctime>Const intmaxn=100005;Doublep[2][MAXN];DoublePRE[MAXN];intN;intm;voidInitintm) { //double T1=clock (); for(intI=1; i<=n;++i) {p[0][i]=1.0/N; } intflag=1; intlim=0; for(intj=1; j<=m;++j) {//if (j%1000==0) printf ("%d\n", j); DoublePre=0; for(inti=lim+1; i<=n;++i) {Pre+=p[flag^1][i-1]; P[flag][i]=p[flag^1][i]*i/n+pre/N; if(p[flag][i]<1e- -) lim=i; } Flag^=1; } //double T2=clock ();}DoubleFintm) { Doubleans=0; for(intI=1; i<=n;++i) {ans+=i*P[m][i]; } returnans;}intMain () {scanf ("%d%d",&n,&m); Init (m); printf ("%.5f\n", Min (f (0), F (1))); return 0;}
Codeforces 453A Little Pony and expected Maximum