codeforces C. Little Pony and Expected Maximum

题意:一个筛子有m个面,然后扔n次,求最大值的期望;

思路:最大值为1 有1种,2有2n-1种,  3有3n -2n 种   所以为m的时有mn -(m-1)n 种,所以分别求每一种的概率,然后乘以这个值求和就可以。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <cmath>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 int n,m;
 9 
10 int main()
11 {
12     cin>>m>>n;
13     double x=pow(1.0/m,n);
14     double ans=x;
15     for(int i=2; i<=m; i++)
16     {
17         double xx=pow(i*1.0/m,n);
18         ans+=(xx-x)*i;
19         x=xx;
20     }
21     printf("%.12lf
",ans);
22     return 0;
23 }
View Code
原文地址:https://www.cnblogs.com/fanminghui/p/4342824.html