1 / * define dp [i] [j] As the number of days to complete i clock, j subsystems required, then it is clear dp [i] [j] is transferred from the four states to 2 P1 = i * J / (n-* S ) . 3 P2 = (Ni) * J / (n-* S) . 4 P3 = I * (SJ) / (n-* S) . 5 P4 = (Ni) * (SJ) / (n-* S) . 6 but for DP [ i] [j], this time apparently dp [i] [j] is 0, can not be transferred, 7 at this time by the method of transposition, the dp [i] [j] to the left, can be obtained dp [i] [j] of the transfer equation 8 state four, * / . 9 #include <the iostream> 10 #include <Queue> . 11 #include <CString> 12 is the using namespace STD; 13 is typedef Long Long LL; 14 const int MAXN = 1E5 +5; 15 double dp[1005][1005]; 16 int main() 17 { 18 int n,s; 19 while(cin>>n>>s) 20 { 21 memset(dp,0,sizeof(dp)); 22 for(int i=n;i>=0;i--) 23 { 24 for(int j=s;j>=0;j--) 25 { 26 if(n==i&&j==s) continue; 27 double p=i*1.0/n;double q=j*1.0/s; 28 //cout <<p<<" "<<q<<endl; 29 dp[i][j]=((1-p)*(1-q)*(dp[i+1][j+1])+(1-p)*q*(dp[i+1][j])+p*(1-q)*(dp[i][j+1])+1)/(1-p*q); 30 } 31 } 32 printf("%.4lf\n",dp[0][0]); 33 } 34 return 0; 35 }