Codeforces 453A Little Pony and expected Maximum

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.