Codeforces - Little Pony and Expected Maximum

题目链接: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;
}
发布了716 篇原创文章 · 获赞 244 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_43826249/article/details/104850642