[Dp] vijos 3747 random probability map

Did not develop according to the state progressive thinking to analyze problems

Title Description

In a map, two I $, $ J Between the probability of generating a $ p $ edge. The probability seeking FIG size $ \ ge 4 $ communication block does not occur.

$ N \ le 100, the answer in the real sense $


Topic analysis

First, it is contemplated that the communication enumeration block size $ $ 1,2,3 points.

One idea is to program the number of combinations in this case is calculated after enumeration of the number of three kinds of points. But this program will be very big number, modulo is not unrealistic.

So should dp to look at this issue, consider adding a probability after each point is how the change. So just talk about the five cases classified just fine.

Focus is to treat this problem with the perspective of dp

 

 1 #include<bits/stdc++.h>
 2 
 3 int n;
 4 double p,q,ans,f[103][103][103];
 5 
 6 double qmi(double a, int b)
 7 {
 8     double ret = 1;
 9     for (; b; b>>=1,a=a*a)
10         if (b&1) ret *= a;
11     return ret;
12 }
13 int main()
14 {
15     scanf("%d%lf",&n,&p);
16     q = (1000.0-p)/1000.0, p /= 1000.0;
17     f[1][0][0] = 1;
18     for (int ix=2,i,j,k; ix<=n; ix++)
19         for (int jx=0; jx<=ix; jx++)
20             for (int kx=0; kx+jx<=ix; kx+=2)
21                 if ((ix-jx-kx)%3==0){
22                     i = jx, j = kx, k = ix-jx-kx;
23                     if (i) f[i][j][k] += qmi(q, ix-1)*f[i-1][j][k];
24                     if (j) f[i][j][k] += qmi(q, ix-2)*p*(i+1.0)*f[i+1][j-2][k];
25                     if (k){
26                         f[i][j][k] += qmi(q, ix-2)*p*(j+2.0)*f[i][j+2][k-3]+qmi(q, ix-3)*p*p*(j/2+1)*f[i][j+2][k-3]+qmi(q, ix-3)*p*p*(i+2.0)*(i+1.0)/2.0*f[i+2][j][k-3];
27                     }
28                 }
29     for (int i=0; i<=n; i++)
30         for (int j=0; i+j<=n; j+=2)
31             if ((n-i-j)%3==0)
32                 ans += f[i][j][n-i-j];
33     printf("%.4lf\n",1.0-ans);
34     return 0;
35 }

 

 

END

 

Guess you like

Origin www.cnblogs.com/antiquality/p/11732648.html