题目链接:Codeforces - Little Pony and Expected Maximum
假设最大值为 k ,那么期望是多少呢? k * (k ^ n - (k-1) ^ n) / m ^ n
就是可能是方案数 / 总方案数 * k
AC代码:
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
int m,n; double res;
signed main(){
cin>>m>>n;
for(double i=1;i<=m;i++) res+=i*(pow(i/m,n)-pow((i-1)/m,n));
printf("%.10lf\n",res);
return 0;
}