1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| #include<bits/stdc++.h> using namespace std; #pragma GCC optimize(2) typedef float db; #define reg register #define rep(i,a,b) for(reg int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(reg int i=a,i##end=b;i>=i##end;--i)
char IO; template <class T=int> T rd(){ T s=0; int f=0; while(!isdigit(IO=getchar())) if(IO=='-') f=1; do s=(s<<1)+(s<<3)+(IO^'0'); while(isdigit(IO=getchar())); return f?-s:s; }
const int INF=1e9+10; const db eps=1e-12;
int n,R,T; struct Edge{ int to,nxt; } e[80000]; int head[410],ecnt; void AddEdge(int u,int v) { e[++ecnt]=(Edge){v,head[u]}; head[u]=ecnt; } db p[410],sz[410],ans[11][11],f[510][210],g[2][2][510],s[2][510];
db h[510][11][11][2];
int main(){ n=rd(),R=rd(),T=rd(); rep(i,1,n*2) { scanf("%f",&p[i]); int e=rd(),f=rd(); sz[i]=e+f+1; rep(j,1,e) { int x=rd(); if(i>n) x+=n; AddEdge(i,x); } rep(j,1,f) { int x=rd(); if(i<=n) x+=n; AddEdge(i,x); } } rep(d,0,1) { f[0][d*n+1]=1; rep(i,0,T) { rep(j,1,n*2) if(f[i][j]>eps) { db t=f[i][j]/sz[j]; for(reg int k=head[j];k;k=e[k].nxt) f[i+1][e[k].to]+=t; f[i+1][j>n?1:n+1]+=t*(1-p[j]); g[d][j>n][i+1]+=t*p[j]; f[i][j]=0; } } rep(i,0,T) { s[d][i]=g[d][0][i]+g[d][1][i]; if(i) s[d][i]+=s[d][i-1]; } } h[0][0][0][0]=1; rep(i,0,T) { rep(a,0,R) rep(b,0,R) rep(j,0,1) if(h[i][a][b][j]>eps) { if(a==R || b==R || i==T){ ans[a][b]+=h[i][a][b][j]; continue; } rep(k,1,T-i) { h[i+k][a+1][b][1]+=h[i][a][b][j]*g[j][0][k]; h[i+k][a][b+1][0]+=h[i][a][b][j]*g[j][1][k]; } ans[a][b]+=h[i][a][b][j]*(1-s[j][T-i]); } } rep(i,0,R) rep(j,0,R) if(i<R || j<R) printf("%.10f\n",ans[i][j]); }
|