Bzoj 3143 HNOI2013 Travel to the hope of extinction

Source: Internet
Author: User

This is the first time I use Gaussian elimination to solve the problem of the expected class, starting a, feel Shuangshuang ....

Chinese topic, do not turn to the careless, directly to the original question:

An undirected connected graph, with vertices numbered from 1 to n, and edges numbered from 1 to M.

  Small Z takes a random walk on the graph, initially small z at Vertex 1th, each step small z randomly selects an edge of the current vertex at an equal probability, and goes along this edge to the next vertex to get a number equal to this edge. When small z reaches the n vertex, the walk ends and the total score is the sum of all the points obtained.

  Now, please number the M-edge, so that small z obtains the lowest total value.

Outputs the minimum total expected value.

Solution:

This greedy is obvious, which side passes the most times the expectation, it should get the smallest number.

So let's say we've already found the expectations of each side, and we can give them a number.

How do you figure out the expectations of each side?

Each side is connected to two points u,v, it is clear that when we pass this edge, must be from one of two points in the entry.

So the expectation of walking through the side = the desired number of passes through the U point * the probability of walking from U point to L + the expected number of passes through the V point * probability of walking from V to L (where the probability of walking from I to the edge of the 1/d[i],d[i] is the degree of i)

i.e.: E[l]=e[u]/d[u]+e[v]/d[v]

But we only know e[n]=0. But we also know what is connected between these points, so that we can draw a relationship between them:

  

We can use the relationship between these points to set up equations, so that the Gaussian elimination of the solution.

Do not forget, the point of the solution will be brought back to each side up oh ....

  

The AC code on the Bzoj (Codevs ... I don't know why ... )

  

/*problem:bzoj 3143 Probability & Gaussian elimination author:robert Yuan memory:15604 kb time:628 MS result:accept*/#include<cmath>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>using namespacestd;#defineMAXN 520structnode{intData,next;} NODE[MAXN*maxn<<1];structedge{intu,v; DoubleW;} EDGE[MAXN*maxn<<1];#defineNow Node[point].data#defineThen Node[point].nextintn,m,cnt;intHEAD[MAXN],DEG[MAXN];Const Doubleeps=1e-6;DoubleW[maxn][maxn],rec_x[maxn],ans;BOOLcmpConstEdge A,ConstEdge B) {    returnA.w>B.W;} Inlineint inch(){    intx=0;CharCh=GetChar ();  while(ch>'9'|| ch<'0') ch=GetChar ();  while(ch>='0'&& ch<='9') x=x*Ten+ch-'0', ch=GetChar (); returnx;}voidAddintUintv) {node[++cnt].data=v;node[cnt].next=head[u];d eg[u]++;head[u]=CNT; node[++CNT].DATA=U;NODE[CNT].NEXT=HEAD[V];d eg[v]++;head[v]=CNT;}voidprework () {n=inch(); m=inch(); intu,v;  for(intI=1; i<=n;i++) head[i]=-1;  for(intI=1; i<=m;i++) U=inch(), v=inch(), edge[i].u=u,edge[i].v=V,add (U,V); intPoint ;  for(intI=1; i<=n;i++) {W[i][i]=1; Point=Head[i];  while(point!=-1) {W[i][now]=-(Double)1/Deg[now]; Point=Then ; }} w[1][n+1]=1;}voidSwap (intIintJintx) {    DoubleT;  for(intk=x+1; k<=n+1; k++) T=w[i][k],w[i][k]=w[j][k],w[j][k]=t;}voidGauss () {inti,j;  for(i=1, j=1; I<=n && j<=n;i++,j++){        intMax_r=i;  for(intk=i+1; k<=n;k++)            if(Fabs (w[max_r][j]) +eps<fabs (w[k][j]) Max_r=K; if(Fabs (W[max_r][j]) <eps) {i--;Continue;} if(max_r!=i) Swap (I,MAX_R,J);  for(intk=i+1; k<=n;k++){            Doublerate=w[k][j]/W[i][j]; W[K][J]=0;  for(intl=j+1; l<=n+1; l++) W[k][l]-=w[i][l]*Rate ; }    }         for(inti=n;i>=1; i--)        if(Fabs (W[i][i]) >EPS) {            Doubleans_c=w[i][n+1];  for(intk=i+1; k<=n;k++) Ans_c-=w[i][k]*Rec_x[k]; Rec_x[i]=ans_c/W[i][i]; }}voidmainwork () {gauss ();  for(intI=1; i<=m;i++) {EDGE[I].W=rec_x[edge[i].u]/deg[edge[i].u]+rec_x[edge[i].v]/DEG[EDGE[I].V]; } Sort (Edge+1, edge+m+1, CMP);  for(intI=1; i<=m;i++) ans+=edge[i].w*i; printf ("%.3LF", ans);}intMain () {#ifndef Online_judge freopen ("x.in","R", stdin);#endifprework ();    Mainwork (); return 0;}
View Code

Bzoj 3143 HNOI2013 Travel to the hope of extinction

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.