Probability question .. You can use either DP or formula.
Abstract questions:
There are n small balls, and the expected number of retrieved small balls is retrieved m times.
DP maintains the two States. The first retrieved is the probability of a ball that has not been taken out. DP [I] and the probability of a ball that has been taken out is NP [I];
If the second I-1 is taken out of the ball has been taken out, then the probability that the second I was not taken out of the ball is DP [I-1];
On the contrary, it is DP [I-1]-1/N (the ball that has not been taken out is missing one)
So we can obtain the state transition equation DP [I] = DP [I-1] * (DP [I-1]-1/n) + NP [I-1] * DP [I-1];
You can also push the formula .. However, I still think that the formula is based on the character. It is of course excellent to be YY-ready...
Code:
#include <iostream>#include <stdio.h>#include<string.h>#include<algorithm>#include<string>#include<math.h>#include<ctype.h>using namespace std;#define MAXN 10000int n,m;double dp[100010];double np[100010];double solve(){ double res=0; memset(dp,0,sizeof(dp)); memset(np,0,sizeof(np)); dp[1]=1; np[1]=0; for(int i=2;i<=m;i++) { dp[i]=dp[i-1]*(dp[i-1]-1.0/(double)n)+np[i-1]*dp[i-1]; np[i]=1-dp[i]; } for(int i=1;i<=m;i++) { res+=dp[i]; } return res;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { printf("%.10lf\n",solve()); } return 0;}
Formula ..
#include <stdio.h>#include<math.h>double n,m;int main(){ while(scanf("%lf%lf",&n,&m)!=EOF) { printf("%.10lf\n",n-n*pow(((n-1)/n),m)); } return 0;}
Sgu495: probability DP/push Formula