Test instructions: There are n disjoint paths between the two places, the section I path consists of the a[i] bridge, each bridge has a probability of damage, allowing you to determine the sequence of detection of all the bridges, so that the total expected number of tests required to minimize.
First of all, obviously detection, is a path to a path to detect, jumping to detect no meaning. Consider the order of a path that is already lined up, and the adjacent two paths J and j+1 if they meet:
(Route[j]. A+ROUTE[J]. B) + (route[j+1]. A+ROUTE[J+1]. B) * (1.0-ROUTE[J].C) >
(Route[j]. A+ROUTE[J]. B) * (1.0-ROUTE[J+1].C) + (route[j+1]. A+ROUTE[J+1]. B
The order in which they are exchanged makes the answer more optimal.
Sweep n times with a similar bubbling method.
A is a good expectation check for all bridges of the Routej, that is, the product of the probability of all bridges multiplied by the number of bridges. B is the Routej bad case of the expected number of detection, equivalent to each bridge damage probability from large to small sort, and then to each bridge K, its front k-1 a bridge all right, it bad probability, multiply k, and then sum this value. C is the product of the probability that all bridges are good, that is, the probability of a good path.
In the final output of the answer, the sum of the probabilities of all paths in front of all paths are bad (a+b).
#include <cstdio> #include <algorithm>using namespace std;struct data{double a,b,c;} Bridge[1005];int n,x[1005];int y[1005];bool cmp (const int &A,CONST int &b) {return a>b;} int main () {//freopen ("c.in", "R", stdin), scanf ("%d", &n), for (int i=1;i<=n;++i) {scanf ("%d", &x[i]);d ouble nowhao=1.0;double huaiall=0;for (int j=1;j<=x[i];++j) {scanf ("%d", &y[j]);} Sort (y+1,y+x[i]+1), for (int j=1;j<=x[i];++j) {huaiall+= (double) j*nowhao* (1.0-(double) y[j]/1000.0); Nowhao*= (( Double) y[j]/1000.0);} Bridge[i]. a=nowhao* (double) x[i];bridge[i]. B=huaiall;bridge[i].c=nowhao;} for (int i=1;i<=n;++i) {for (int j=1;j<n;++j) {if (Bridge[j]. A+BRIDGE[J]. B) + (bridge[j+1]. A+BRIDGE[J+1]. B) * (1.0-BRIDGE[J].C) > (Bridge[j]. A+BRIDGE[J]. B) * (1.0-BRIDGE[J+1].C) + (bridge[j+1]. A+BRIDGE[J+1]. B) {swap (bridge[j],bridge[j+1]);}}} Double ans=0;double now=1.0;double sum=0;for (int i=1;i<=n;++i) {ans+=now* (Bridge[i]. A+bridge[i]. B); now*= (1.0-BRIDGE[I].C);} printf ("%.10f\n", ans); return 0;}
Derivation "mathematical expectation" "bubble sort" Petrozavodsk Winter Training Camp 2018 Day 5:grand Prix of Korea, Sunday, February 4, 2018 problem C. Earthquake