P1933"poetize3" mung Bean Frog's home time: 1000ms/Space: 131072kib/java class name: Main background with the new version of Baidu Space online, blog pet mung Bean Frog completed its mission, to find its new destination. The description gives a direction-free graph with a starting point of 1 ending at N, each edge having a length, and starting from the beginning to reach all points, all points can also reach the end point. The mung bean frog starts from the starting point and goes to the end.
At each vertex, if there is a road where K leaves the point, the mung bean Frog can choose any route to leave the point, and the probability of going to each road is 1/k.
Now mung bean frog want to know, from the starting point to the end of the path through the total length of the expectation is what? Input format First line: Two integers n m, representing n points, M edges in the graph
The second line to line 1+m: 3 integers a b c per line, representing the expected value from a to B with a forward-side output format of length C from the beginning to the end path total length, rounded to retain two decimal places. Test Sample 1 input
4 4
1 2 1
1 3 2
2 3 3
3 4 4
Output
7.00
Note for 20% of data n<=100
For 40% of data n<=1000
For 60% of data n<=10000
For 100% data n<=100000,m<=2*n —————— I'm a gorgeous split line ——————————————
Mathematical Expectations
DPGood problem, difficult problem. Very confusing.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <queue>7#include <cstdlib>8#include <iomanip>9#include <cassert>Ten#include <climits> One #defineMAXN 10001 A #defineF (i,j,k) for (int i=j;i<=k;i++) - #defineM (A, B) memset (A,b,sizeof (a)) - #defineFF (i,j,k) for (int i=j;i>=k;i--) the #defineINF 0x7fffffff - using namespacestd; - intRead () { - intx=0, f=1;CharCh=GetChar (); + while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} + returnx*F; A } at structedge{ - intTo,w,next; -}p[200010]; - intTot,n; - inthead[100010]; - voidAddedge (intAintBintc) { inp[tot].to=b; -p[tot].w=C; top[tot].next=Head[a]; +head[a]=tot++; - } the Doubledp[100010]; * int out[100010],q[100010]; $ intout1[100010];Panax Notoginseng intMain () - { theStd::ios::sync_with_stdio (false);//cout<<setiosflags (ios::fixed) <<setprecision (1) <<y; + //freopen ("data.in", "R", stdin); A //freopen ("Data.out", "w", stdout); the intm,a,b,c; +Cin>>n>>m; -M (head,-1); $ while(m--){ $Cin>>a>>b>>C; - Addedge (b,a,c); - out[a]=++Out1[a]; the } - ints=0, e=-1;Wuyiq[++e]=N; the while(s<=e) { -s++; Wu intu=Q[s]; - for(inti=head[u];i!=-1; i=P[i].next) { About intv=p[i].to; $dp[v]+= (DP[U]+P[I].W)/ out[v]; - if(--out1[v]==0) q[++e]=v; - } - } ACout<<setiosflags (iOS::fixed) <<setprecision (2) <<dp[1]; +cout<<Endl; the return 0; -}
View Code
TYVJ P1933 mung Bean Frog's final destination (unfinished)