codeforces 453 A. Little Pony and Expected Maximum
http://codeforces.com/problemset/problem/453/A
题意:m面筛子,每面点数出现的概率相同,连续投掷n次,问出现的最大值的数学期望。
思路:手写样例。。。发现答案为
。。。记得把(1/m)^n放进去。
观察答案,可以这样理解(我是用样例推出公式后理解。。。数学差的人心好累):如果i为最大值,那么n次每次必须投掷出1..i的点数,概率为 (i/m)^n,但是要至少有一个投掷成i,也就是要减去所有的数都是1..i-1中的情况(概率 为((i-1)/m)^n),
1/* ***********************************************
2Author :111qqz
3Created Time :2016年02月02日 星期二 05时17分24秒
4File Name :code/cf/problem/453A.cpp
5************************************************ */
6
7#include <cstdio>
8#include <cstring>
9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=1E5+7;
34double ans;
35int n ,m;
36double p1[N],p2[N];
37int main()
38{
39 #ifndef ONLINE_JUDGE
40 freopen("code/in.txt","r",stdin);
41 #endif
42
43 cin>>m>>n;
44 ans = 0;
45 for ( int i = 1 ; i <= m ; i++)
46 {
47 ans +=i*(pow(i*1.0/m,n*1.0)-pow((i-1)*1.0/m,n*1.0));
48 }
49 printf("%.10f\n",ans);
50
51 #ifndef ONLINE_JUDGE
52 fclose(stdin);
53 #endif
54 return 0;
55}