• bzoj1415 NOI2005聪聪和可可


    %%%http://hzwer.com/2819.html

    先各种暴力搞出来p[x][y](从x到y下一个最近应该到达的位子)

    然后就记忆化搜索??(雾)

     1 #include<bits/stdc++.h>
     2 #define LL long long
     3 #define LD long double  
     4 #define  N 100005
     5 using namespace std;
     6 inline int ra()
     7 {
     8     int x=0,f=1; char ch=getchar();
     9     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
    10     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    11     return x*f;
    12 }
    13 const int M=1001;
    14 int n,m,cnt,a,b;
    15 int head[M],d[M],q[N];
    16 int dis[M][M],p[M][M];
    17 double f[M][M];
    18 struct node{
    19     int to,next;
    20 }e[M<<1];
    21 void insert(int x, int y)
    22 {
    23     e[++cnt].to=y;
    24     e[cnt].next=head[x];
    25     head[x]=cnt;
    26     d[x]++;
    27 }
    28 double dp(int x, int y)
    29 {
    30     if (f[x][y]) return f[x][y];
    31     if (x==y) return 0;
    32     if (p[x][y]==y || p[p[x][y]][y]==y) return f[x][y]=1;
    33     double tot=dp(p[p[x][y]][y],y);
    34     for (int i=head[y];i;i=e[i].next)
    35         tot+=dp(p[p[x][y]][y],e[i].to);
    36     return f[x][y]=tot/(d[y]+1)+1;
    37 }
    38 void bfs(int x)
    39 {
    40     int l=0,r=1;
    41     q[0]=x; dis[x][x]=0;
    42     while (l<r)
    43     {
    44         int now=q[l++],tmp=p[x][now];
    45         for (int i=head[now];i;i=e[i].next)
    46             if (dis[x][e[i].to]==-1 || (1+dis[x][now]==dis[x][e[i].to] && tmp<p[x][e[i].to]))
    47             {
    48                 dis[x][e[i].to]=dis[x][now]+1;
    49                 p[x][e[i].to]=tmp;
    50                 if (!tmp) p[x][e[i].to]=e[i].to;
    51                 q[r++]=e[i].to;
    52             }
    53     }
    54 }
    55 int main()
    56 {
    57     memset(dis,-1,sizeof(dis));
    58     n=ra(); m=ra(); a=ra(); b=ra();
    59     for (int i=1; i<=m; i++)
    60     {
    61         int x=ra(),y=ra();
    62         insert(x,y); insert(y,x);
    63     }
    64     for (int i=1; i<=n; i++) bfs(i);
    65     printf("%.3lf",dp(a,b));
    66     return 0;
    67 }
  • 相关阅读:
    Atitit 图像金字塔原理与概率 attilax的理解总结qb23
    Atitit.软件中见算法 程序设计五大种类算法
    百度之星
    linux下编程IDE环境
    c++多态的实现 VC++消息映射的实现
    static_cast, const_cast,dynamic_cast和reinterpret_cast
    X Window研究笔记(1)~22
    关于串口发送短信
    模式识别中的核方法
    IC设计,verilog学习链接
  • 原文地址:https://www.cnblogs.com/ccd2333/p/6369680.html
Copyright © 2020-2023  润新知