BZOJ3640:JC's Little Apple

Source: Internet
Author: User

Description

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.

P.S. We all know that this series is to improve the group simulation, so this is a sub-problem to send Balabala

Input

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

Only one line, which means JC finds the expected probability of his little apple, retains eight decimal places.

Layer the graph by HP remainder, use F[A][W] to represent HP remaining A, the probability of the current point W reaching the end

Recursion is only related to the current layer and the smaller layer of HP, and the preprocessing is inverse to the recursive matrix of the parts related to the current layer, so O (n^2) can transfer a layer

Time complexity O (N^3+N^2*HP)

#include <bits/stdc++.h>typedefDoubleld;intn,m,hp,vs[155];std::vector<int>es[155];ld f[10007][155],xs[155][155],ys[155],zs[155][155];voidAeintAintb) {    if(a==n)return; ++Xs[a][a]; if(Vs[b]) es[a].push_back (b); Else--xs[a][b];}intMain () {scanf ("%d%d%d",&n,&m,&hp);  for(intI=1; i<=n;++i) scanf ("%d", vs+i), zs[i][i]=1;  for(intI=0, a,b;i<m;++i) {scanf ("%d%d",&a,&b); AE (A, b);if(a!=b) AE (b,a); } Xs[n][n]=1;  for(intI=1; i<=n;++i) {        intw=i;  for(intj=i+1; j<=n;++j)if(Fabs (Xs[j][i]) >fabs (Xs[w][i]) w=J; if(w!=i) for(intj=1; j<=n;++j)            {Std::swap (xs[i][j],xs[w][j]);        Std::swap (Zs[i][j],zs[w][j]); } LD a=Xs[i][i];  for(intj=1; j<=n;++j) {Xs[i][j]/=A; ZS[I][J]/=A; }         for(intj=1; j<=n;++j)if(j!=i) {a=Xs[j][i];  for(intk=1; k<=n;++k) {Xs[j][k]-=xs[i][k]*A; ZS[J][K]-=zs[i][k]*A; }        }    }     for(intt=1; t<=hp;++t) {         for(intI=1; i<n;++i) {Ys[i]=0;  for(intj=0; J<es[i].size (); + +j) {                intu=Es[i][j]; if(vs[u]<t) ys[i]+=f[t-Vs[u]]            [u]; }} Ys[n]=1;  for(intI=1; i<=n;++i) {ld s=0;  for(intj=1; j<=n;++j) s+=zs[i][j]*Ys[j]; F[t][i]=s; }} printf ("%.8f\n", f[hp][1]); return 0;}

BZOJ3640:JC's Little Apple

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.