POJ 2096 Collecting Bugs

期望,$dp$。

设$dp[i][j]$表示已经发现$i$种$bug$,$j$个程序中的$bug$到达目标状态需要的期望天数。则$dp[i][j]=dp[i][j]*i*j/(n*s)+dp[i][j+1]*i*(s-j)/(n*s)+dp[i+1][j]*(n-i)*j/(n*s)+dp[i+1][j+1]*(n-i)*(s-i)/(n*s)+1$。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c = getchar();
    x = 0;
    while(!isdigit(c)) c = getchar();
    while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
}

double dp[1005][1005];
int n,s;

int main()
{
    while(~scanf("%d%d",&n,&s))
    {
        memset(dp,0,sizeof dp);

        for(int i=n;i>=0;i--)
        {
            for(int j=s;j>=0;j--)
            {
                if(i==n&&j==s) continue;

                dp[i][j]=dp[i][j+1]*i*(s-j)/(n*s)
                        +dp[i+1][j]*(n-i)*j/(n*s)
                        +dp[i+1][j+1]*(n-i)*(s-j)/(n*s)
                        +1;

                dp[i][j]=dp[i][j]/(1-1.0*i*j/(n*s));
            }
        }
        printf("%.4f\n",dp[0][0]);
    }
    return 0;
}

 

posted @ 2017-01-18 13:33  Fighting_Heart  阅读(137)  评论(0编辑  收藏  举报