zoukankan      html  css  js  c++  java
  • [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
    %.2Lf
    ",Calc1(),Calc2());
  • 相关阅读:
    selenium中webDriver模块的常用方法
    java web Project Explorer误删解决方法
    java web开发前后端中文配置
    常见Filed Types
    类的展现
    面向对象:类与运算符
    面向对象定义类,属性
    筛选元素
    try : finally语句
    捕获异常try:except
  • 原文地址:https://www.cnblogs.com/Gster/p/5090521.html
Copyright © 2011-2022 走看看