Let's continue the story of JC and Dzy.
"You are my little ya little Apple, how to love you are not too much!" ”
"Light the fire of my life, fire fire! ”
JC came to City B after a hard slog, but Dzy stole his little Apple because of his negligence! No small apple How to listen to the song! He found that the evil Dzy hid his little apple in a maze. JC was left with HP blood after his previous battle. Start JC at Point 1th, his little Apple at the N number point. Dzy put monsters in some points. When JC encounters the monster in I, he loses the AI point blood. When JC's blood is equal to 0 o'clock, he is automatically ejected from the maze and can no longer enter.
But JC lost, he can only from the current point of departure and other probability of the choice of a road to go. All roads are two-way, there are M-bars, monsters cannot be killed. Now JC wants to know the odds of him finding his little apple.
Input format:
The first line of three integers represents n,m,hp. The next line of integers, section I, indicates the amount of blood to be lost from JC to point I. Ensure that the number of 1th and N is 0. The next M-line of two integers per line, A, B, has a non-forward edge between AB.
Output format:
Only one line, which means JC finds the expected probability of his little apple, retains eight decimal places.
Sample input:
3 3 2 0 1 0 1 2 1 3 2 3
Sample output:
0.87500000
Data range:
For 10% of data n=5,hp=1
For 30% of data n<=20,hp<=5
For 60% of data n<=50,hp<=10000
For another 10% of the data has a bit of power is positive
For 100% of data 2<=n<=150,hp<=10000,m<=5000, ensure that the map Unicom, the right to the point of non-negative.
Time limit:
4s
Space limitations:
256M
Embarrassed, at first do not know the point of power is not negative, is later added to, ask others just know
Copy the puzzle (too lazy to write, the puzzle is much better than me):
"Algorithm One"
Search (although I do not know how to search) expected score 10
"Algorithm Two"
Put all points according to HP split, then Gaussian elimination, Complexity O (hp^3*n^3). The desired score 30
"Algorithm three"
We found that for HP there is a DAG between layers and layers, so each layer does Gaussian elimination. Then recursion between layers and layers is possible. Complexity O (hp*n^3), desired score 60
"Algorithm Four"
Roughly the same as the algorithm three, but we found that each Gaussian elimination of the matrix in addition to the constant term is the same, so you can first Gaussian elimination of the pretreatment, the other as long as the work can be done. Complexity O (hp*n^2), desired score 100
Embarrassed, since the ring too silent, can only add one, can not add two times
1 Const2maxn= the;3maxm=5050;4maxhp=10010;5eps=1e-9;6 var7X, Y:Array[0.. MAXN,0.. MAXN] ofDouble;8F:Array[0.. MAXHP,0.. MAXN] ofDouble;9Ff:Array[0.. MAXN] ofDouble;TenA,d,first:Array[0.. MAXN] ofLongint; OneLast,next:Array[0.. maxm*2] ofLongint; A N,m,hp,tot:longint; - ans:double; - the procedureInsert (x,y:longint); - begin - ifX=n Thenexit; - Inc (TOT); +last[tot]:=y; -next[tot]:=First[x]; +first[x]:=tot; A Inc (D[x]); at End; - - procedureSwapvarx,y:double); - var - t:double; - begin int:=x;x:=y;y:=T; - End; to + procedureWork ; - var the I,j,k:longint; * s:double; $ beginPanax Notoginseng fori:=1 toN Do - begin thej:=First[i]; + whileJ<>0 Do A begin the ifa[last[j]]=0 Thenx[last[j],i]:=x[last[j],i]-1/D[i]; +j:=Next[j]; - End; $ End; $ fori:=1 toN Dox[i,i]:=x[i,i]+1; - fori:=1 toN Doy[i,i]:=1; - fori:=1 toN-1 Do the begin - forJ:=i toN DoWuyi ifABS (X[j,i]) >eps ThenBreak ; the fork:=1 toN Doswap (x[i,k],x[j,k]); - fork:=1 toN Doswap (y[i,k],y[j,k]); Wu forj:=i+1 toN Do - ifABS (X[j,i]) >eps Then About begin $s:=x[j,i]/X[i,i]; - fork:=1 toN Dox[j,k]:=x[j,k]-x[i,k]*s; - fork:=1 toN Doy[j,k]:=y[j,k]-y[i,k]*s; - End; A End; + forI:=nDownto 2 Do the forj:=1 toI-1 Do - ifABS (X[j,i]) >eps Then $ begin thes:=x[j,i]/X[i,i]; the fork:=1 toN Dox[j,k]:=x[j,k]-x[i,k]*s; the fork:=1 toN Doy[j,k]:=y[j,k]-y[i,k]*s; the End; - fori:=1 toN Do in forj:=1 toN Do they[i,j]:=y[i,j]/X[i,i]; the End; About the proceduremain; the var the I,j,k,u,v:longint; + begin - read (N,M,HP); the fori:=1 toN Doread (a[i]);Bayi fori:=1 toM Do the begin the read (u,v); - ifU<>v ThenInsert (u,v); - Insert (v,u); the End; the Work ; theF[HP,1]:=1; the forI:=hpDownto 1 Do - begin theff:=F[i]; theans:=ans+ff[n];ff[n]:=0; the forj:=1 toN Dof[i,j]:=0;94 forj:=1 toN Do the fork:=1 toN Do thef[i,j]:=f[i,j]+ff[k]*Y[j,k]; theans:=ans+f[i,n];f[i,n]:=0;98 forj:=1 toN Do About begin -k:=First[j];101 whileK<>0 Do102 begin103 if(i-a[last[k]]>0) and(a[last[k]]>0) Then104f[i-a[last[k]],last[k]]:=f[i-a[last[k]],last[k]]+f[i,j]/D[j]; thek:=Next[k];106 End;107 End;108 End;109Writeln (ans:0:8); the End;111 the begin113 main; the End.
View Code
Update: Bzoj on the topic, but Pascal has been card, think of N long, helpless to pay STD (c + +), suddenly thought of an optimization, 15s+ card (good bitterness AH)