zoukankan      html  css  js  c++  java
  • poj 2096 Collecting Bugs 概率DP

                        Collecting Bugs
    Time Limit: 10000MS   Memory Limit: 64000K
    Total Submissions: 3379   Accepted: 1672
    Case Time Limit: 2000MS   Special Judge

    Description

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stuff, he collects software bugs. When Ivan gets a new program, he classifies all possible bugs into n categories. Each day he discovers exactly one bug in the program and adds information about it and its category into a spreadsheet. When he finds bugs in all bug categories, he calls the program disgusting, publishes this spreadsheet on his home page, and forgets completely about the program. 
    Two companies, Macrosoft and Microhard are in tight competition. Microhard wants to decrease sales of one Macrosoft program. They hire Ivan to prove that the program in question is disgusting. However, Ivan has a complicated problem. This new program has s subcomponents, and finding bugs of all types in each subcomponent would take too long before the target could be reached. So Ivan and Microhard agreed to use a simpler criteria --- Ivan should find at least one bug in each subsystem and at least one bug of each category. 
    Macrosoft knows about these plans and it wants to estimate the time that is required for Ivan to call its program disgusting. It's important because the company releases a new version soon, so it can correct its plans and release it quicker. Nobody would be interested in Ivan's opinion about the reliability of the obsolete version. 
    A bug found in the program can be of any category with equal probability. Similarly, the bug can be found in any given subsystem with equal probability. Any particular bug cannot belong to two different categories or happen simultaneously in two different subsystems. The number of bugs in the program is almost infinite, so the probability of finding a new bug of some category in some subsystem does not reduce after finding any number of bugs of that category in that subsystem. 
    Find an average time (in days of Ivan's work) required to name the program disgusting.

    Input

    Input file contains two integer numbers, n and s (0 < n, s <= 1 000).

    Output

    Output the expectation of the Ivan's working days needed to call the program disgusting, accurate to 4 digits after the decimal point.

    Sample Input

    1 2

    Sample Output

    3.0000

    Source

    Northeastern Europe 2004, Northern Subregion
     
     
     
     
    题意:一个软件有 s 个子系统,存在 n 种 bug。某人一天能找到一个 bug。问,在这个软件中找齐 n 种 bug,并且每个子系统中至少包含一个 bug 的时间的期望值(单位:天)。注意:bug 是无限多的,每个 bug 属于任何一种 bug 的概率都是 1/n;出现在每个系统是等可能的,为 1/s。
     
    令dp[i][j]表示还剩下i个子系统的bugs,j种bugs没有找到的状态下的期望值。
    初始化:dp[0][0]=0.0
    求:dp[s][n]
     
    状态转移方程:
    在状态(i,j)时,找到一个新的bug,有4种可能
    1.新的子系统的,新的种类的
    2.新的子系统的,旧的种类的
    3.旧的子系统的,新的种类的
    4.旧的子系统的,旧的种类的
     
    对于每一种的概率:
    以s,n为x,y轴上的点,建立一个坐标轴,则由几何概型(即面积占总面积的比例):
    1. i * j / ( n * s ) 
    2. i * ( n - j ) / ( n * s )
    3. ( s - i ) * j / ( n * s )
    4. ( s - i ) * ( n - j ) / ( n * s )
     
     
    则可以得到状态转移方程,移项,递推即可解。
     
     
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 
     5 using namespace std;
     6 
     7 const int maxn=1010;
     8 const int maxs=1010;
     9 
    10 double dp[maxs][maxn];
    11 
    12 int n,s;
    13 
    14 inline double ret(double x,double y)
    15 {
    16     return x*y/((double)n*s);
    17 }
    18 
    19 int main()
    20 {
    21     while(~scanf("%d%d",&n,&s))
    22     {
    23         dp[0][0]=0.0;
    24         for(int i=0;i<=s;i++)
    25         {
    26             for(int j=0;j<=n;j++)
    27             {
    28                 dp[i][j]=0.0;
    29                 if(i>0&&j>0)
    30                     dp[i][j]+=ret(i,j)*dp[i-1][j-1];
    31                 if(i>0)
    32                     dp[i][j]+=ret(i,n-j)*dp[i-1][j];
    33                 if(j>0)
    34                     dp[i][j]+=ret(j,s-i)*dp[i][j-1];
    35                 if(i!=0||j!=0)
    36                 {
    37                     dp[i][j]+=1.0;
    38                     dp[i][j]=dp[i][j]/(1.0-ret(s-i,n-j));
    39                 }
    40             }
    41         }
    42         printf("%.4f
    ",dp[s][n]);
    43     }
    44     return 0;
    45 }
    View Code
     
     
     
     
     
     
     
  • 相关阅读:
    一个小demo的开发日记(二)
    一个小demo的开发日记(一)
    一个小demo的开发日记(〇)
    基本光照与阴影(一)
    图形渲染管线与shader(更新中)
    近期的一些进展ww
    2016-4-10
    2D游戏中常见的碰撞检测处理(仅碰撞体)【持续更新】
    智能车。。一个可以取代二值化操作的比较好用的函数
    C++
  • 原文地址:https://www.cnblogs.com/-maybe/p/4681044.html
Copyright © 2011-2022 走看看