Algoogle

Algorithm for Programming Contest

Codeforces 453A Little Pony and Expected Maximum

Category: Codeforces Tag: probabilities

Little Pony and Expected Maximum

問題概要


m面サイコロをn回投げた時の最大値の期待値

解法


コード


(453A.cpp) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i,a) repi(i,0,a)

int n, m;
double ans, p, q;

double solve(){
    if(m==1) return 1.;
    ans = 0; p = m; q = n;
    rep(i,m) {
        double k = i+1;
        ans += k*(pow(k/p,q)-pow(1.*i/p,q));
    }
    return ans;
}

void input(){
    cin >> m >> n;
}

int main(){
    cin.sync_with_stdio(0);
    cout << fixed << setprecision(12);
    input();
    cout << solve() << endl;
    return 0;
}

Comments