标签:
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5159
题意:
给定你1~a, 一共a个数 ,又b次操作每次从中有放回取出一个,
然后求最后取出的数的不重复的数的和的期望
eg 取出{1,2,1} 最后和为3;
取出{1,2,3} 最后和为6;
分析;
E = sum(i*Pi) (1<=i<=a);
Pi 表示i在这b次中出现的概率
Pi = 1 - (1 - 1/a)^b;
由于pi都相等 因此
E= (1+a)*a/2*pi;
代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
int main()
{
int t,cas=1;
scanf("%d",&t);
while(t--){
long long a,b;
scanf("%I64d%I64d",&a,&b);
double p =1 - pow((a-1)/(1.0*a),b*1.0);
long long sum = (a+1)*a/2;
double ans = sum * p;
printf("Case #%d: %.3lf\n",cas++,ans);
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/bigbigship/article/details/42609735