几道概率dp

来源:互联网 发布:python 游戏 编辑:程序博客网 时间:2024/06/18 17:33

POJ2096 Collecting Bugs
有n种bug,s个子构件,每次等可能抽到其中1子构件的1种bug
求抽到全部种类和子构件的期望

#include<cstdio>#include<algorithm>using namespace std;int n, s;double f[1010][1010]; //n bug s ssy 期望 int main(){    scanf("%d%d", &n, &s);    f[n][s] = 0;    for(int i=n; i>=0; i--)        for(int j=s; j>=0; j--)        {            if(i==n&&j==s) continue;            f[i][j] = ((n-i)*j*f[i+1][j]                     +(i*(s-j))*f[i][j+1]                     +(n-i)*(s-j)*f[i+1][j+1]+n*s)                     /(n*s-i*j);        }    printf("%.4lf", f[0][0]);    return 0;}