HDU 4035 2011 All network Tournament e probability DP * * * *

Source: Internet
Author: User

It's too much, I won't.

1 /*2 HDU 40353 4 DP asks for the desired question. 5 Test Instructions:6 there were n rooms, connected by the N-1 Tunnel, which actually formed a tree,7 Starting from Node 1, start walking, there are 3 possibilities in each node I:8 1. Be killed, return to Node 1 (probability is Ki)9 2. Find the exit and get out of the maze (probability is EI)Ten 3. And the point is connected with M-edge, random walk a bar One ask: Out of the maze of the number of sides to go to the expected value.  A  - Set E[i] indicates the expectation of the number of sides to go out of the maze at node I. E[1] is the request.  -  the leaf knot: - E[i] = ki*e[1] + ei*0 + (1-ki-ei) * (E[father[i]] + 1); - = ki*e[1] + (1-ki-ei) *e[father[i]] + (1-KI-EI); -  + Non-leaf nodes: (M is the number of sides connected to the node) - E[i] = ki*e[1] + ei*0 + (1-ki-ei)/m* (e[father[i]]+1 +∑ (e[child[i]]+1)); + = ki*e[1] + (1-ki-ei)/m*e[father[i] + (1-ki-ei)/m*∑ (E[child[i]]) + (1-ki-ei); A  at set to each node: e[i] = ai*e[1] + bi*e[father[i] + Ci; -  - for non-leaf node I, set the child node of J for I, then - ∑ (E[child[i]) =∑e[j] - =∑ (aj*e[1] + bj*e[father[j] + Cj) - =∑ (aj*e[1] + bj*e[i] + Cj) in to bring in the above formula - (1-(1-ki-ei)/m*∑bj) *e[i] = (ki+ (1-ki-ei)/m*∑aj) *e[1] + (1-ki-ei)/m*e[father[i]] + (1-ki-ei) + (1-ki-ei)/m*∑cj;< /c10> to this will get + Ai = (ki+ (1-ki-ei)/m*∑aj)/(1-(1-ki-ei)/M*∑BJ); - Bi = (1-ki-ei)/M/(1-(1-ki-ei)/M*∑BJ); the Ci = ((1-ki-ei) + (1-ki-ei)/M*∑CJ)/(1-(1-ki-ei)/M*∑BJ); *  $ for the leaf knot.Panax Notoginseng Ai = ki; - Bi = 1-ki-ei; the Ci = 1-ki-ei; +  A start from the leaf node until the a1,b1,c1 is calculated; the  + e[1] = a1*e[1] + b1*0 + C1; - so $ e[1] = C1/(1-A1); $ If the A1 is approaching 1, there is no solution ... -  - */ the#include <stdio.h> -#include <string.h>Wuyi#include <algorithm> the#include <iostream> -#include <math.h> Wu#include <vector> - using namespacestd; About Const intmaxn=10010; $ Const Doubleeps=1e-9;//here 1e-8 will WA. Set to 1e-9 and 1e-10 to - DoubleK[MAXN],E[MAXN]; - DoubleA[MAXN],B[MAXN],C[MAXN]; -  Avector<int>vec[MAXN];//Save Tree +  the BOOLDfsintTintPre//the root node of T is the pre . - { $     intM=vec[t].size ();//the degree of the point T thea[t]=K[t]; theB[t]= (1-K[T]-E[T])/m; thec[t]=1-k[t]-E[t]; the     Doubletmp=0; -      for(intI=0; i<m;i++) in     { the         intv=Vec[t][i]; the         if(V==pre)Continue; About         if(!dfs (v,t))return false; thea[t]+= (1-k[t]-e[t])/m*A[v]; thec[t]+= (1-k[t]-e[t])/m*C[v]; thetmp+= (1-k[t]-e[t])/m*B[v]; +     } -     if(Fabs (tmp-1) <eps)return false; theA[t]/= (1-tmp);BayiB[t]/= (1-tmp); theC[t]/= (1-tmp); the     return true; - } - intMain () the { the    //freopen ("In.txt", "R", stdin); the    //freopen ("OUT.txt", "w", stdout); the     intT; -     intN; the     intu,v; the     intIcase=0; thescanf"%d",&T);94      while(t--) the     { theicase++; thescanf"%d",&n);98          for(intI=1; i<=n;i++) vec[i].clear (); About          for(intI=1; i<n;i++) -         {101scanf"%d%d",&u,&v);102 Vec[u].push_back (v);103 vec[v].push_back (u);104         } the          for(intI=1; i<=n;i++)106         {107scanf"%LF%LF",&k[i],&e[i]);108K[i]/= -;109E[i]/= -; the         }111printf"Case %d:", icase); the         if(Dfs (1,-1) &&fabs (1-a[1]) >EPS)113         { theprintf"%.6lf\n", c[1]/(1-a[1])); the         } the         Elseprintf"impossible\n");117     }118}

HDU 4035 2011 All network Tournament e 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.