题意:给出一个DAG,一只机器人从1点出发,等概率地选择一条出边走或者停留在原点,机器人的第k次行动消耗能量是k(无论是走还是停留都算一次行动)。问1到n的期望。

解法:因为行动消耗的能量跟行动次数有关(有点像求E(x^2)的味道),考虑做两次概率DP。

dp1[x]表示点x到终点n的期望天数,那么dp1[x]=( dp1[x]+sigma(dp1[y]) ) / (du+1) + 1 。(du是x点度数,y是x儿子)。

dp2[x]表示点x到终点n的期望代价,那么dp2[x]=( dp2[x]+dp1[x]+1 + sigma(dp2[y]+dp1[y]+1) ) / (du+1)。(du和y同上)

先求dp1之后求dp2,答案就是dp2[1]。

代码写得很丑:

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+;
int n,m;
vector<int> G[N]; double dp1[N],dp2[N];
void dfs1(int x) {
if (x==n) return;
if (dp1[x]!=) return;
double tmp=;
for (int i=;i<G[x].size();i++) {
int y=G[x][i];
dfs1(y);
tmp+=dp1[y];
}
tmp+=G[x].size()+;
tmp/=(double)G[x].size();
dp1[x]=tmp;
} void dfs2(int x) {
if (x==n) return;
if (dp2[x]!=) return;
double tmp=;
for (int i=;i<G[x].size();i++) {
int y=G[x][i];
dfs2(y);
tmp+=dp2[y]+dp1[y]+;
}
tmp+=dp1[x]+;
tmp/=(double)G[x].size();
dp2[x]=tmp;
} int main()
{
int T; cin>>T;
while (T--) {
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++) G[i].clear();
for (int i=;i<=m;i++) {
int x,y; scanf("%d%d",&x,&y);
G[x].push_back(y);
}
for (int i=;i<=n;i++) dp1[i]=dp2[i]=;
dfs1();
dfs2();
printf("%.2lf\n",dp2[]);
}
return ;
}

The Preliminary Contest for ICPC Asia Nanjing 2019 D. Robots的更多相关文章

  1. The Preliminary Contest for ICPC Asia Nanjing 2019 - D Robots(概率dp+拓扑排序)

    这题概率dp + 拓扑排序可以写 改天补解释 #include <bits/stdc++.h> using namespace std; const int maxn=1e5+10; ve ...

  2. The Preliminary Contest for ICPC Asia Nanjing 2019/2019南京网络赛——题解

    (施工中……已更新DF) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出 ...

  3. [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)

    >传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...

  4. 计蒜客 The Preliminary Contest for ICPC Asia Nanjing 2019

    F    Greedy Sequence You're given a permutation aa of length nn (1 \le n \le 10^51≤n≤105). For each  ...

  5. The Preliminary Contest for ICPC Asia Nanjing 2019

    传送门 A. The beautiful values of the palace 题意: 给出一个\(n*n\)的矩阵,并满足\(n\)为奇数,矩阵中的数从右上角开始往下,类似于蛇形填数那样来填充. ...

  6. The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail

    题目链接:https://nanti.jisuanke.com/t/41305 题目说的很明白...只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了... #include < ...

  7. The Preliminary Contest for ICPC Asia Nanjing 2019 B. super_log (广义欧拉降幂)

    In Complexity theory, some functions are nearly O(1)O(1), but it is greater then O(1)O(1). For examp ...

  8. 树状数组+二维前缀和(A.The beautiful values of the palace)--The Preliminary Contest for ICPC Asia Nanjing 2019

    题意: 给你螺旋型的矩阵,告诉你那几个点有值,问你某一个矩阵区间的和是多少. 思路: 以后记住:二维前缀和sort+树状数组就行了!!!. #define IOS ios_base::sync_wit ...

  9. B.super_log(The Preliminary Contest for ICPC Asia Nanjing 2019)

    同:https://www.cnblogs.com/--HPY-7m/p/11444923.html #define IOS ios_base::sync_with_stdio(0); cin.tie ...

随机推荐

  1. sqlserver 之 将查询结果变为json字符串

    GO /****** Object: StoredProcedure [dbo].[SerializeJSON] Script Date: 6/4/2019 3:58:23 PM 将查询结果变为jso ...

  2. DC/DCT/DCG 差别和联系

    在dc家族系列中,DC_V,DC_E为根本的DC(Design Compiler)对象,具有dc所具有的根本fearture,DC在synopys对象系列中地位,无足轻重,也是业界应用最普遍的综合对象 ...

  3. I/O性能优化

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11525014.html Linux 系统的 I/O 栈图 I/O性能指标 根据指标找工具 根据工具查指 ...

  4. 【leetcode】1023. Binary String With Substrings Representing 1 To N

    题目如下: Given a binary string S (a string consisting only of '0' and '1's) and a positive integer N, r ...

  5. CNN笔记:通俗理解卷积神经网络

    CNN笔记:通俗理解卷积神经网络 2016年07月02日 22:14:50 v_JULY_v 阅读数 250368更多 分类专栏: 30.Machine L & Deep Learning 机 ...

  6. 使用C#实现网站用户登录

    我们在写灌水机器人.抓资源机器人和Web网游辅助工具的时候第一步要实现的就是用户登录.那么怎么用C#来模拟一个用户的登录拉?要实现用户的登录,那么首先就必须要了解一般网站中是怎么判断用户是否登录的.H ...

  7. Ant Design(ui框架)

    官方文档:https://ant.design/docs/react/introduce-cn 说明:Ant Design 是一个 ui框架,和 bootstrap 一样是ui框架.里面的组件很完善, ...

  8. mysql使用crontab定时备份

    1, 安装crontab yum install vixie-cron yum install crontabs 说明:vixie-cron软件包是cron的主程序:crontabs软件包是用来安装. ...

  9. linux远程管理器 - xshell和xftp使用教程(zhuan)

    准备好连接linux服务器的工具,推荐用xshell和xftp. xshell 是一个强大的安全终端模拟软件,它支持SSH1, SSH2, 以及Microsoft Windows 平台的TELNET ...

  10. app自动化生成测试报告

    1.首先导入from BeautifulReport import BeautifulReport 参考:https://www.cnblogs.com/may18/p/10445162.html 2 ...