Test instructions
There are n nodes of the graph, beginning to have some edges exist, now arbitrarily choose two points a day to even one edge (may have been connected), to make the entire graph to connect the desired number of days.
Analysis:
Since the start diagram can be seen as a few connected components, and a previous problem is thought, a point represents a set (here is the connected component) for compression
Dp[i][s] represents the last connection of the first I unicom components, Unicom State is the expected number of days, dp[0][1], that is, as the answer, because s may be large, with the memory of the search
#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cctype>#include<complex>#include<cassert>#include<utility>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespaceStd;typedef pair<int,int>Pii;typedefLong Longll;#defineLson l,m,rt<<1#definePi ACOs (-1.0)#defineRson m+1,r,rt<<11#defineAll 1,n,1#defineN 50#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007; Vector<int>E[n];intUsed[n],num[n],n,m,len;map<int,Double>Dp[n];//count the number of nodes for each connected componentintDfsintu) {Used[u]=1; intTotal=1; for(intI=0; I<e[u].size (); + +i) { if(!Used[e[u][i]] Total+=DFS (E[u][i]); } returnTotal ;}//Memory SearchDoubleSolveintIints) { if(Dp[i].count (s))returnDp[i][s]; intliantong=0; //number of nodes currently in China Unicom for(intj=0; j<len;++j) { if(s& (1<<j)) Liantong+=Num[j]; } if(liantong==n)returndp[i][s]=0; //average number of days required to select a non-connected pointdp[i][s]=1.0* (n1)/(nLiantong); //Select an disconnected unicom component for(intj=0; j<len;++j) { if(! (s& (1<<j))) Dp[i][s]+=solve (j,s| (1<<J)) *num[j]/(nLiantong); } returndp[i][s];}intMain () {intt,cas=0; scanf ("%d",&t); while(t--) {scanf ("%d%d",&n,&m); intu,v; memset (Used,0,sizeof(used)); memset (num,0,sizeof(num)); for(intI=1; i<=n;++i) e[i].clear (); while(m--) {scanf ("%d%d",&u,&v); E[u].push_back (v); E[v].push_back (U); } Len=0; for(intI=1; i<=n;++i) { if(Used[i])Continue; Dp[len].clear (); Num[len++]=DFS (i); } printf ("Case %d:%.6lf\n", ++cas, Solve (0,1)); }return 0;}
UVA 11600-masud Rana (like pressure, probability dp)