A program has an unlimited number of bugs, one day can find 1, these bugs have two different keywords, a, B, respectively, according to the two keywords are divided into n and m species, to collect all classes (summon the dragon) of the desired days
DP[I][J] Indicates that I have collected the expected days of type A and J B
Dp[i][j]=i/n*j/s*dp[i][j]+p
p= (n-i)/n*j/s*dp[i+1][j]+i/n* (s-j)/s*dp[i][j+1]+ (n-i)/n* (s-j)/s*dp[i+1][j+1]+1
dp[i][j]=p*n*s/of moving items (N*S-I*J)
When N*s=i*j, the dog takes
ANS=DP[0][0]
Deep understanding of the Kuangbin Uncle said to seek more than the reverse push Qaq
1#include <cstdio>2 using namespacestd;3 #defineMAXN 10054 DoubleDP[MAXN][MAXN];5 intMain () {6 intn,s;7 while(SCANF ("%d%d", &n,&s)! =EOF) {8dp[n][s]=0;9 for(inti=n;i>=0; i--)Ten for(intj=s;j>=0; j--){ One if(N*S==I*J)Continue; Adp[i][j]=dp[i+1][j]* (n-i)/n*j/s+dp[i][j+1]*i/n* (S-J)/s+dp[i+1][j+1]* (n-i)/n* (s-j)/s+1; -dp[i][j]*=1.0*n*s/(n*s-i*j); - } theprintf"%.4lf\n", dp[0][0]); - } - return 0; -}
View Code
[POJ 2096] Collecting Bugs