• bzoj1415


    比较简单的数学期望,先预处理出当聪聪在i,可可在j时聪聪往哪个点走
    然后做dp即可,我用了记忆化搜索实现

      1 type node=record
      2        po,next:longint;
      3      end;
      4 
      5 var d,pos:array[0..1010,0..1010] of longint;
      6     f:array[0..1010,0..1010] of double;
      7     v:array[0..1010] of boolean;
      8     e:array[0..2010] of node;
      9     c,p,q:array[0..2010] of longint;
     10     len,s,t,i,j,n,m,x,y:longint;
     11 
     12 procedure add(x,y:longint);
     13   begin
     14     inc(len);
     15     e[len].po:=y;
     16     e[len].next:=p[x];
     17     p[x]:=len;
     18   end;
     19 
     20 procedure bfs(s:longint);
     21   var f,r,i,x,y:longint;
     22   begin
     23     d[s,s]:=0;
     24     fillchar(v,sizeof(v),false);
     25     v[s]:=true;
     26     f:=1;
     27     r:=0;
     28     i:=p[s];
     29     while i<>0 do
     30     begin
     31       y:=e[i].po;
     32       v[y]:=true;
     33       inc(r);
     34       q[r]:=y;
     35       d[s,y]:=1;
     36       pos[s,y]:=y;
     37       i:=e[i].next;
     38     end;
     39     while f<=r do
     40     begin
     41       x:=q[f];
     42       i:=p[x];
     43       while i<>0 do
     44       begin
     45         y:=e[i].po;
     46         if not v[y] then
     47         begin
     48           d[s,y]:=d[s,x]+1;
     49           pos[s,y]:=pos[s,x];
     50           v[y]:=true;
     51           inc(r);
     52           q[r]:=y;
     53         end
     54         else if (d[s,y]=d[s,x]+1) and (pos[s,x]<pos[s,y]) then
     55           pos[s,y]:=pos[s,x];
     56 
     57         i:=e[i].next;
     58       end;
     59       inc(f);
     60     end;
     61   end;
     62 
     63 function dfs(x,y:longint):double;
     64   var i,w:longint;
     65   begin
     66     if x=y then exit(0);
     67     if (pos[x,y]=y) or (pos[pos[x,y],y]=y) then exit(1);
     68     if f[x,y]<>-1 then exit(f[x,y]);
     69     i:=p[y];
     70     f[x,y]:=dfs(pos[pos[x,y],y],y);
     71     while i<>0 do
     72     begin
     73       w:=e[i].po;
     74       f[x,y]:=f[x,y]+dfs(pos[pos[x,y],y],w);
     75       i:=e[i].next;
     76     end;
     77     f[x,y]:=f[x,y]/(c[y]+1)+1;
     78     exit(f[x,y]);
     79   end;
     80 
     81 begin
     82   readln(n,m);
     83   readln(s,t);
     84   for i:=1 to m do
     85   begin
     86     readln(x,y);
     87     add(x,y);
     88     add(y,x);
     89     inc(c[x]);
     90     inc(c[y]);
     91   end;
     92   for i:=1 to n do
     93   begin
     94     for j:=1 to n do
     95       f[i,j]:=-1;
     96     pos[i,i]:=i;
     97     f[i,i]:=0;
     98     bfs(i);
     99   end;
    100   writeln(dfs(s,t):0:3);
    101 end.
    View Code
  • 相关阅读:
    VS2019 开发CMake项目
    node实验1
    DX9动画加载
    Excel表格的自动化处理和推送(二)信息分发
    案例分享:Excel表格的自动化处理和推送
    快速信息分发应用分发工资条明细
    在EasySQLMAIL中实现表格的行列转置
    从命令行启动EasySQLMAIL中的信息推送任务
    version `GLIBCXX_3.4.20' not found 解决方法
    【面试系列】如何保障质量之测试左移右移
  • 原文地址:https://www.cnblogs.com/phile/p/4473008.html
Copyright © 2020-2023  润新知