题意:这个骰子有M面:骰子的第一面有一个点,第二面有两个点,以此类推,第m面含有M点。暮暮确信的是,当掷骰子时,每一面都有1/m的可能性出现,并且每次投掷的概率都是都是独立的。请你帮助她计算掷N次骰子后每次得到的点数中最大值的期望。、
思路:考虑直接枚举最大值为i的情况,根据期望的定义得出ans等于各个最大值乘以该最大值出现的概率,而最大值为i的情况总共有i的n次方减去(i-1)的n次方。计算的时候直接用pow函数即可
/*keep on going and never give up*/
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef pair<int, int> pii;
#define int long long
#define lowbit(x) x&(-x)
#define endl '\n'
#define wk is zqx ta die
signed main() {
// std::ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
int m, n;
cin >> m >> n;
double ans = 0;
for (int i = 1; i <= m; i++) {
ans += 1.0 * i * (pow(1.0 * i / m, n) - pow(1.0 * (i - 1) / m, n));
}
printf("%.10lf\n", ans);
return 0;
}