Title Link: http://www.lydsy.com:808/JudgeOnline/problem.php?id=3640
Test instructions: Gives an no-go graph, from 1 to N. The start is the amount of blood H, from u to v when the amount of blood decreased a[v]. Each path is equal in probability. The probability of going to N and the amount of blood greater than 0.
Idea: Setting F[h][u] indicates the probability of reaching the U blood volume H. Since some points arrive without losing blood, this is not easy to get. List the equations, and find out which points of each non-bleeding point arrive as well as their coefficients. For example, x, Y, Z can reach R,r point not to lose blood, then f[h][r]=p1*f[h][x]+p2*f[h][y]+p3*f[h][z]. This p1, p2, p3 is the coefficient of R. The inverse matrix can be obtained.
const int n=155; int N,m,k,b[n],a[n];d ouble x[n][n],num[n][n],f[11111][n];int a[n][n]; void Gauss () {int i,j,k; for (i=1;i<=n;i++) {for (j=i;j<=n;j++) if (Fabs (X[j][i]) >1e-10) break; if (j!=i) {for (k=1;k<=n;k++) {swap (x[i][k],x[j][k]); Swap (num[i][k],num[j][k]); }} double tmp=x[i][i]; for (k=1;k<=n;k++) x[i][k]/=tmp,num[i][k]/=tmp; for (j=1;j<=n;j++) if (j!=i) {tmp=x[j][i]; for (k=1;k<=n;k++) x[j][k]-=x[i][k]*tmp,num[j][k]-=num[i][k]*tmp; }}}int Main () {scanf ("%d%d%d", &n,&m,&k); int i,j,k; for (i=1;i<=n;i++) scanf ("%d", &a[i]); for (i=1;i<=m;i++) {int x, y; scanf ("%d%d", &x,&y); b[x]++; a[x][y]++; if (x!=y) {b[y]++; a[y][x]++; }} for (i=1;i<n;i++) for (j=1;j<=n;j++) if (! A[J]) x[j][i]-=1.0*a[i][j]/b[i]; for (i=1;i<=n;i++) x[i][i]+=1,num[i][i]=1; Gauss (); F[k][1]=1; Double ans=0; for (k=k;k>=1;k--) {for (i=1;i<n;i++) for (j=1;j<=n;j++) if (A[j]&&k+a[j]<=k&&b[i]) {f[k][j]+=f[k+a[j]][i]*a[i][j]/(b[i]); } double cs[n]; for (i=1;i<=n;i++) cs[i]=f[k][i]; for (i=1;i<=n;i++) if (! A[i]) {f[k][i]=0; for (j=1;j<=n;j++) if (a[j]| | j==1) F[k][i]+=num[i][j]*cs[j]; } Ans+=f[k][n]; } printf ("%.8lf\n", ans); return 0;}
Bzoj 3640 JC's small apple (inverse matrix)