绿豆蛙的归宿

思路:

  topsort+期望dp;

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 100005 int head[maxn],cnt,E[maxn<<],V[maxn<<],du[maxn];
int sta[maxn],top,n,m; double W[maxn<<],dp[maxn][],num[maxn]; inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} inline void edge_add(int u,int v,double w)
{
E[++cnt]=head[u],V[cnt]=v,W[cnt]=w,head[u]=cnt;
} int main()
{
in(n),in(m);int u,v;double w;
for(;m--;)
{
in(u),in(v),du[v]++;
num[u]+=1.0;
scanf("%lf",&w);
edge_add(u,v,w);
}
dp[][]=,sta[++top]=;
while(top>)
{
int now=sta[top--];
for(int i=head[now];i;i=E[i])
{
dp[V[i]][]+=dp[now][]/num[now],du[V[i]]--;
dp[V[i]][]+=(dp[now][]*W[i]+dp[now][])/num[now];
if(!du[V[i]]) sta[++top]=V[i];
}
}
printf("%.2lf",dp[n][]);
return ;
}

AC日记——绿豆蛙的归宿 codevs 2488的更多相关文章

  1. codevs 2488 绿豆蛙的归宿

    2488 绿豆蛙的归宿 http://codevs.cn/problem/2488/  时间限制: 1 s  空间限制: 64000 KB  题目等级 : 黄金 Gold   题目描述 Descrip ...

  2. 2488 绿豆蛙的归宿(拓扑+dp)

    488 绿豆蛙的归宿  时间限制: 1 s  空间限制: 64000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 随着新版百度空间的上线,Blog宠物绿豆 ...

  3. 【BZOJ 3036】 3036: 绿豆蛙的归宿 (概率DP)

    3036: 绿豆蛙的归宿 Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 491  Solved: 354 Description 随着新版百度空间的下线 ...

  4. 【BZOJ3036】绿豆蛙的归宿 拓补排序+概率

    [BZOJ3036]绿豆蛙的归宿 Description 随着新版百度空间的下线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度. ...

  5. BZOJ3036: 绿豆蛙的归宿&Wikioi2488:绿豆蛙的归宿

    3036: 绿豆蛙的归宿 Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 108  Solved: 73[Submit][Status] Descript ...

  6. BZOJ 3036: 绿豆蛙的归宿( 期望dp )

    从终点往起点倒推 . 在一个图 考虑点 u , 出度为 s : s = 0 , d[ u ] = 0 ; s ≠ 0 , 则 d( u ) = ( ∑ d( v ) ) / s ( ( u , v ) ...

  7. BZOJ3036绿豆蛙的归宿

    BZOJ3036绿豆蛙的归宿 锲下陟凝 褰宓万 郝瓦痕膳 叶诙摞 А知π剧 椐猊∫距 屠缲佗 ゲ蕖揪 俜欧彖鹤 磲砩ほ #琛扶 觅电闸ス 捆鳢げ 浜窠 魂睨"烁 蕞滗浼 洒ヂ跪 ...

  8. [COGS 1065] 绿豆蛙的归宿

    先贴题面w 1065. [Nescafe19] 绿豆蛙的归宿 ★   输入文件:ldfrog.in   输出文件:ldfrog.out   简单对比时间限制:1 s   内存限制:128 MB 随着新 ...

  9. P4316 绿豆蛙的归宿(期望)

    P4316 绿豆蛙的归宿 因为非要用bfs所以稍微麻烦一点qwq(大家用的都是dfs) 其实问题让我们求的就是经过每条边的概率*边权之和 我们可以用bfs把图遍历一遍处理概率,顺便把每条边的概率*边权 ...

随机推荐

  1. php 文件上传失败

    使用OSX系统,在使用MAMP Pro作为虚拟服务器,并使用PHP作为后端语言进行文件上传,从临时文件夹拷贝文件的方法为 move_uploaded_file 代码如下: if($_FILES['fi ...

  2. [CF1076E]Vasya and a Tree

    题目大意:给定一棵以$1$为根的树,$m$次操作,第$i$次为对以$v_i$为根的深度小于等于$d_i$的子树的所有节点权值加$x_i$.最后输出每个节点的值 题解:可以把操作离线,每次开始遍历到一个 ...

  3. [NOIP2018 TG D2T1]旅行

    题目大意:$NOIP\;TG\;D2T1$ 题解:一棵树的很简单,第一个点一定是$1$,只需要对每个节点,找最小的没有访问过的节点访问即可,我写的是$O(n\log_2n)$. 考虑基环树的部分,一个 ...

  4. linux管理(二)---网络使用情况的监控

    我们经常在监控服务器或者排查程序性能瓶颈时需要知道  网络带宽的使用情况,看看带宽是不是瓶颈. linux系统中监控网络的工具和命令很多. 但其实主要分2种,一种是实时监控带宽情况(速度如何),一种是 ...

  5. wya费用流

    #include<bits/stdc++.h> using namespace std; #define M 1005 #define inf 0x7fffffff #define T 6 ...

  6. API网关Kong部署和使用文档

    KONG安装使用说明 系统版本:ubuntu14 1.下载安装包 $ wget https://github.com/Mashape/kong/releases/download/0.8.3/kong ...

  7. Avito Cool Challenge 2018 A. B题解

    A. Definite Game 题目链接:https://codeforces.com/contest/1081/problem/A 题意: 给出一个数v,然后让你可以重复多次减去一个数d,满足v% ...

  8. java的哈希遍历 hashmap

    Map<String,String> map = new HashMap<String, String>(); map.put("title"," ...

  9. async的用法

    package com.example.administrator.myapplication; import android.os.AsyncTask; import android.util.Lo ...

  10. Terminals Project

    https://github.com/Terminals-Origin Terminals Project Terminals is a secure, multi tab terminal serv ...