这句话感觉都能成定理了:
xor问题逐位考虑……
这道题就是这样,然后和bzoj3143和相似
但这道题多了自环,于是我们设f[i]表示当前位由i走到n的后为1的数学期望
显然f[n]=0,可得f[i]=sigma((1/d[i])*f[j])(如果边权这位为0)+sigma((1/d[i])*(1-f[j]))(边权这位为1)
然后高斯消元即可

 1 type node=record
 2        po,len,next:longint;
 3      end;
 4 
 5 var w:array[0..20010] of node;
 6     b,d,p:array[0..110] of longint;
 7     a:array[0..110,0..110] of extended;
 8     n,m,x,y,z,len,t,i,j,k:longint;
 9     c,ans:extended;
10 
11 function max(a,b:longint):longint;
12   begin
13     if a>b then exit(a) else exit(b);
14   end;
15 
16 procedure swap(var a,b:extended);
17   var c:extended;
18   begin
19     c:=a;
20     a:=b;
21     b:=c;
22   end;
23 
24 procedure add(x,y,z:longint);
25   begin
26     inc(len);
27     w[len].po:=y;
28     w[len].len:=z;
29     w[len].next:=p[x];
30     p[x]:=len;
31   end;
32 
33 procedure work;
34   var i,j,k,p:longint;
35   begin
36     for i:=1 to n-2 do
37     begin
38       p:=i;
39       for k:=i+1 to n-1 do
40         if abs(a[k,i])>abs(a[p,i]) then p:=k;
41       if p<>i then
42       begin
43         for j:=i to n+1 do
44           swap(a[p,j],a[i,j]);
45       end;
46       for k:=i+1 to n-1 do
47         if abs(a[k,i])>0 then
48         begin
49           for j:=n+1 downto i do
50             a[k,j]:=a[k,j]-a[i,j]*a[k,i]/a[i,i];
51         end;
52     end;
53     a[n,n+1]:=0;
54     for i:=n-1 downto 1 do
55     begin
56       for j:=i+1 to n-1 do
57         a[i,n+1]:=a[i,n+1]-a[j,n+1]*a[i,j];
58       a[i,n+1]:=a[i,n+1]/a[i,i];
59     end;
60   end;
61 
62 begin
63   readln(n,m);
64   for i:=1 to m do
65   begin
66     readln(x,y,z);
67     if z<>0 then t:=max(t,trunc(ln(z)/ln(2)));
68     inc(d[x]);
69     inc(d[y]);
70     if x=y then dec(d[x])
71     else add(y,x,z);
72     add(x,y,z);
73   end;
74   for i:=0 to t do
75   begin
76     fillchar(a,sizeof(a),0);
77     for j:=1 to n do
78       a[j,j]:=1;
79     for k:=1 to n do
80     begin
81       j:=p[k];
82       while j<>0 do
83       begin
84         y:=w[j].po;
85         if w[j].len and (1 shl i)=0 then a[k,y]:=a[k,y]-1/d[k]
86         else begin
87           a[k,y]:=a[k,y]+1/d[k];
88           a[k,n+1]:=a[k,n+1]+1/d[k];
89         end;
90         j:=w[j].next;
91       end;
92     end;
93     work;
94     ans:=ans+1 shl i*a[1,n+1];
95   end;
96   writeln(ans:0:3);
97 end.
View Code

 

posted on 2015-01-09 22:58  acphile  阅读(184)  评论(0编辑  收藏  举报