zoukankan      html  css  js  c++  java
  • 概率与期望

    绿豆蛙的期望

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    
    const int maxn=100000+10;
    
    struct my{
        int next;
        int v;
        double w;
    };
    
    bool vis[maxn];
    int dp[maxn];
    int tot,adj[maxn];
    int n,m;
    double totans;
    int in[maxn];
    my edge[maxn*2];
    
    void myinsert(int u,int v,int w){
         edge[++tot].next=adj[u];
         edge[tot].v=v;
         edge[tot].w=w;
         adj[u]=tot;
         in[u]++;
    }
    
    double dfs(int x){
           if(x==n) return 0;
           //vis[x]=true;
           double ans=0;
           for (int i=adj[x];i;i=edge[i].next){
                int v=edge[i].v;
             //   if(vis[v]) continue;
                ans+=(dfs(v)+edge[i].w)/in[x];
           }
           //totans+=ans;
           return ans;
    }
    
    int main(){
        int u,v,w;
        scanf("%d%d",&n,&m);
        for (int i=1;i<=m;i++){
            scanf("%d%d%d",&u,&v,&w);
            myinsert(u,v,w);
        }
        //dfs(1);
        printf("%.2lf
    ",dfs(1));
    return 0;
    }
  • 相关阅读:
    ElementUi
    Vue插件
    Vue-cli
    Vue进阶
    Vue组件
    Vue生命期钩子
    Vue基础
    Vue介绍
    logging模块
    time模块
  • 原文地址:https://www.cnblogs.com/lmjer/p/9801116.html
Copyright © 2011-2022 走看看