UVA 11600-masud Rana (like pressure, probability dp)

Source: Internet
Author: User

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&LT;&LT;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.