[poj2096]Collecting Bugs
定义状态f[i][j]表示发现了i种bug在j台电脑上后期望多少天能结束,$f[i][j]=(ij\cdot f[i][j]+(n-i+1)j\cdot f[i+1][j]+i(m-j+1)\cdot f[i][j+1]+(n-i+1)(m-j+1)\cdot f[i+1][j+1])/(ns)+1$,解得$f[i][j]=(ns+(n-i+1)j\cdot f[i+1][j]+i(m-j+1)\cdot f[i][j+1]+(n-i+1)(m-j+1)\cdot f[i+1][j+1])/(ns-ij)$
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,m; 4 double f[1005][1005]; 5 int main(){ 6 scanf("%d%d",&n,&m); 7 for(int i=n;i>=0;i--) 8 for(int j=m;j>=0;j--) 9 if ((i!=n)||(j!=m)) 10 f[i][j]=1.0*(n*m+i*(m-j)*f[i][j+1]+(n-i)*j*f[i+1][j]+(n-i)*(m-j)*f[i+1][j+1])/(n*m-i*j); 11 printf("%.4f",f[0][0]); 12 }