zoukankan      html  css  js  c++  java
  • SGU495 概率DP

    Kids and Prizes 

    ICPC (International Cardboard Producing Company) is in the business of producing cardboard boxes. Recently the company organized a contest for kids for the best design of a cardboard box and selected M winners. There are N prizes for the winners, each one carefully packed in a cardboard box (made by the ICPC, of course). The awarding process will be as follows: 
    • All the boxes with prizes will be stored in a separate room. 
    • The winners will enter the room, one at a time. 
    • Each winner selects one of the boxes. 
    • The selected box is opened by a representative of the organizing committee. 
    • If the box contains a prize, the winner takes it. 
    • If the box is empty (because the same box has already been selected by one or more previous winners), the winner will instead get a certificate printed on a sheet of excellent cardboard (made by ICPC, of course). 
    • Whether there is a prize or not, the box is re-sealed and returned to the room. 
    The management of the company would like to know how many prizes will be given by the above process. It is assumed that each winner picks a box at random and that all boxes are equally likely to be picked. Compute the mathematical expectation of the number of prizes given (the certificates are not counted as prizes, of course). 

    Input
    The first and only line of the input file contains the values of N and M ( ). 

    Output
    The first and only line of the output file should contain a single real number: the expected number of prizes given out. The answer is accepted as correct if either the absolute or the relative error is less than or equal to 10 -9. 

    Example(s)
    input:
    5 7
    4 3
    output:
    3.951424
    2.3125
    题意:
    
    有n个奖品,m个人排队来选礼物,对于每个人,他打开的盒子,可能有礼物,也有可能已经被之前的人取走了,然后把盒子放回原处。为最后m个人取走礼物的期望。
    思路:
    
    排队取,第1个人取到1个,dp[1]=1;后面的人dp[i]=p取到礼物盒子+dp前面的取到礼物盒子=(n-dp[i-1])/n + dp[i-1];
     1 #include"bits/stdc++.h"
     2 
     3 #define db double
     4 #define ll long long
     5 #define vl vector<ll>
     6 #define ci(x) scanf("%d",&x)
     7 #define cd(x) scanf("%lf",&x)
     8 #define cl(x) scanf("%lld",&x)
     9 #define pi(x) printf("%d
    ",x)
    10 #define pd(x) printf("%f
    ",x)
    11 #define pl(x) printf("%lld
    ",x)
    12 #define rep(i, n) for(int i=0;i<n;i++)
    13 using namespace std;
    14 const int N   = 1e6 + 5;
    15 const int mod = 1e9 + 7;
    16 const int MOD = 998244353;
    17 const db  PI  = acos(-1.0);
    18 const db  eps = 1e-10;
    19 const ll INF = 0x3fffffffffffffff;
    20 int t;
    21 db dp[N];
    22 int n,m;
    23 void cal()
    24 {
    25     dp[1]=1;
    26     for(int i=2;i<=m;i++) dp[i]=dp[i-1]+(n-dp[i-1])/n;
    27     printf("%f
    ",dp[m]);
    28 }
    29 int main()
    30 {
    31 
    32     while(scanf("%d%d",&n,&m)==2){
    33         cal();
    34     }
    35     return 0;
    36 }
  • 相关阅读:
    森林病虫防治系统 (七)
    森林病虫防治系统 (六)
    森林病虫防治系统 (五)
    森林病虫防治系统 (四)
    森林病虫防治系统 (三)
    森林病虫防治系统 (二.2)
    森林病虫防治系统 (二.1)
    森林病虫防治系统(二)
    森林病虫防治系统 (一)
    java web 机试
  • 原文地址:https://www.cnblogs.com/mj-liylho/p/9535958.html
Copyright © 2011-2022 走看看