之前我们曾经用dp解决过数学期望问题,这次我们用的是解方程的方法
首先在编号之前,肯定要求出每条边的期望经过次数然后可以转化为求边端点的期望次数这种做法我一开始接触是noip2013的初赛问题求解,是类似的思想当出现循环无法用dp解决时,我们考虑列方程设pi为点i的期望经过次数则容易得到pi=sigma(pj/dj) dj表示出度,j是与i相邻的点特殊的p1=1+sigma(pj/dj) pn=0(因为到n就停止了)于是我们可以得到一个方程组,这样就可以用高斯消元求解解出之后就能求出边的期望经过次数了,然后贪心分配编号即可1 var w:array[0..510,0..510] of longint; 2 a:array[0..510,0..510] of double; 3 x,y:array[0..300010] of longint; 4 c,p:array[0..300010] of double; 5 d:array[0..510] of longint; 6 i,j,k,n,m:longint; 7 ans:double; 8 9 procedure swap(var a,b:double);10 var c:double;11 begin12 c:=a;13 a:=b;14 b:=c;15 end;16 17 procedure calc;18 var i,j,k,w:longint;19 begin20 for i:=1 to n do21 begin22 w:=i;23 for k:=i+1 to n do24 if abs(a[k,i])>abs(a[w,i]) then w:=k;25 if w<>i then26 begin27 for j:=1 to n+1 do28 swap(a[w,j],a[i,j]);29 end;30 for k:=i+1 to n do31 for j:=n+1 downto i do32 a[k,j]:=a[k,j]-a[i,j]*a[k,i]/a[i,i];33 end;34 p[n]:=0;35 for i:=n-1 downto 1 do36 begin37 for j:=i+1 to n do38 a[i,n+1]:=a[i,n+1]-a[i,j]*p[j];39 p[i]:=a[i,n+1]/a[i,i];40 end;41 end;42 43 procedure sort(l,r: longint);44 var i,j: longint;45 x:double;46 begin47 i:=l;48 j:=r;49 x:=c[(l+r) shr 1];50 repeat51 while c[i]j) then54 begin55 swap(c[i],c[j]);56 inc(i);57 j:=j-1;58 end;59 until i>j;60 if l