POJ 2096-Collecting Bugs(概率dp入门)

题意:

有n种bug和s种系统bug,每天发现一种bug(可能已经发现过了)所有种bug被发现的概率相同,求所有bug被发现的期望天数。

分析:

dp[i][j]发现i种bug,j种系统bug期望天数,dp[n][s]=0;dp[0][0]即为所求

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

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
#define N 1010
const ll  INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod =  1000000007;
using namespace std;
double dp[N][N];
int n, s;
double solve(){
    dp[n][s] = 0.0;
    for(int i = n; i >= 0; i--) {
        for(int j = s; j >= 0; j--)
        {
            if(i == n && j == s)continue;
            dp[i][j] = (n-i)*(s-j)*dp[i+1][j+1] + i*(s-j)*dp[i][j+1] + (n-i)*j*dp[i+1][j] + n*s;
            dp[i][j] /= n*s - i*j;
        }
    }
    return dp[0][0];
}
int main() {
    while(~scanf("%d%d",&n,&s))
        printf("%.4f\n", solve());
    return 0;
}

 

转载于:https://www.cnblogs.com/zsf123/p/4737867.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值