[TS-A1489][2013中国国家集训队第二次作业]抽奖[概率dp]

概率dp第一题,开始根本没搞懂,后来看了09年汤可因论文才基本搞懂,关键就是递推的时候做差比较一下,考虑新加入的情况对期望值的贡献,然后推推公式(好像还是不太会推qaq...)

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int    n,m;
 6 long double    a[110000];
 7 
 8 long double    POW(const long double t,int b)
 9 {
10     long double    r=1,base=t;
11     while(b)
12     {
13         if(b&1)r*=base;
14         base*=base;
15         b>>=1;
16     }
17     return r;
18 }
19 
20 long double    Calc1()
21 {
22     long double    temp=0;
23     for(int i=1;i<=n;++i)temp+=a[i]*a[i];
24     return (double)m*(m-1)*temp+m;
25 }
26 
27 long double    Calc2()
28 {
29     long double    temp=0;
30     for(int i=1;i<=n;++i)temp+=POW(1-a[i],m);
31     return (double)n-temp;
32 }
33 
34 int main()
35 {
36     int    i;
37     int    Sum=0;
38     scanf("%d%d",&n,&m);
39     for(i=1;i<=n;++i)scanf("%Lf",&a[i]),Sum+=a[i];
40     for(i=1;i<=n;++i)a[i]=a[i]/Sum;
41     printf("%.2Lf\n%.2Lf\n",Calc1(),Calc2());

 

posted @ 2015-12-31 02:28  Gster  阅读(226)  评论(0编辑  收藏  举报