Codeforces 453A Little Pony and Expected Maximum 概率期望
来源:互联网 发布:网络语言黑洞什么意思 编辑:程序博客网 时间:2024/05/23 02:00
做完这个题才发现自己是个大水货,当时CF的时候,一个小时没有把这个题推出来,结果刚刚推出来码代码码好了,测试数据也过了,已提交,Contest Over,我就呵呵了,具体做法不难,就是一点数学功底,求期望,有1到n的n个数,取到每个数的概率为1/n,并且取m次,每次取到后还要放回,问你取m次中最大的数的数学期望,由于自己渣一般的数学功底,当时就怕了,但是仔细一想,还是可推的,我们可以设置比如我们取到最大的数为i,那么我们m次取得的数字必须是前面i个数,即取到的概率为(i/n)^m,但是这个答案还包含了之前i-1个数的情况,所以处理方法使每次继续累加前面情况的概率sum,算得取到最大数为i的概率即为(i/n)^m-sum,再乘以i即为当前情况的期望,从1循环到n即可得到总的期望值。。。PS:乘方运算必须使用矩阵快速幂,否则还是会TLE滴。。。具体程序如下:
#include<cstdio>#include<iostream>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>using namespace std;double cal(double a,int b){ double ans=1,it=a; while(b>0) { if(b&1) ans=ans*it; it=it*it; b>>=1; } return ans;}double dp[10005];int main(){ // freopen("in.txt","r",stdin); int n,m; while(cin>>n>>m) { double ans=0,p=0; double pa=cal(1.0/n,m),sum=0; ans+=pa; sum+=pa; for(int i=2;i<=n;i++) { pa=(cal(((double)(i)/n),m))-sum; sum+=pa; ans+=pa*i; } printf("%.12lf\n",ans); } return 0;}
0 0
- Codeforces 453A Little Pony and Expected Maximum 概率期望
- Codeforces 453A Little Pony and Expected Maximum(期望)
- codeforces 453A Little Pony and Expected Maximum 最大值期望
- codeforces 453A Little Pony and Expected Maximum(期望)
- codeforces 453A. Little Pony and Expected Maximum (概率与期望+快速幂)
- [概率DP] Codeforces 453A Little Pony and Expected Maximum
- 【CF 453A】 Little Pony and Expected Maximum (最大期望)
- Codeforces 453A Little Pony and Expected Maximum 概率题Orz
- Codeforces 453A Little Pony and Expected Maximum
- Codeforces 453A. Little Pony and Expected Maximum
- Codeforces 453 A. Little Pony and Expected Maximum
- codeforces 453-A Little Pony and Expected Maximum
- 【codeforces】 453A Little Pony and Expected Maximum
- Codeforces 453A Little Pony and Expected Maximum
- Codeforces 453A Little Pony and Expected Maximum
- CodeForces 453A Little Pony and Expected Maximum
- Codeforces 453 A. Little Pony and Expected Maximum
- Codeforces 454C Little Pony and Expected Maximum 简单期望
- 花心雨的世界
- Spring实例化Bean的三种方式
- redis数据结构
- 1058. A+B in Hogwarts (20)
- 关于strtok的一点简单认识
- Codeforces 453A Little Pony and Expected Maximum 概率期望
- Linux Shortcut Key
- [DFS][toj1009Sticks]
- [编程之美] PSet2.11 寻找最近点对
- 并查集及并查集的路径压缩
- 菜鸟学习javaweb(二)--可变参数
- EAS数据库IO等待分析及优化报告
- iOS 如何选择delegate、notification、KVO?
- 出栈和入栈方向