这题概率dp + 拓扑排序可以写

改天补解释

#include <bits/stdc++.h>
using namespace std; const int maxn=1e5+10;
vector<int>vec[maxn];
int indeg[maxn],seq[maxn];
double d[maxn],f[maxn];
int N,M,T,tot=0; void topo()
{
queue<int>q;
q.push(1);
tot=0;
seq[tot++]=1;
while (!q.empty()) {
int u=q.front();
q.pop();
for (int i=0;i<vec[u].size();i++) {
if (--indeg[vec[u][i]]==0) {
q.push(vec[u][i]);
seq[tot++]=vec[u][i];
}
}
}
} int main()
{
scanf("%d",&T);
while (T--) {
scanf("%d%d",&N,&M);
for (int i=1;i<=N;i++) {
vec[i].clear();
}
memset(indeg,0,sizeof(indeg));
for (int i=0;i<=N;i++) {
d[i]=0;
f[i]=0;
}
int x,y;
for(int i=0;i<M;i++) {
scanf("%d%d",&x,&y);
vec[x].push_back(y);
indeg[y]++;
}
topo();
for (int i=tot-2;i>=0;i--) {
int u=seq[i];
int cnt=vec[u].size()+1;
for (int j=0;j<cnt-1;j++) {
d[u]+=d[vec[u][j]];
}
d[u]=(d[u]/(double)cnt+1)*(double)cnt/(double)(cnt-1);
}
for (int i=tot-2;i>=0;i--) {
int u=seq[i];
int cnt=vec[u].size()+1;
for (int j=0;j<cnt-1;j++) {
f[u]+=f[vec[u][j]];
}
f[u]+=cnt*d[u];
f[u]=f[u]/(double)(cnt-1);
}
printf("%.2lf\n",f[1]);
}
return 0;
}

最新文章

  1. Stanford NLP 学习笔记2:文本处理基础(text processing)
  2. Semantic UI – 完全语义化的前端界面开发框架
  3. remove() 方法的兼容问题
  4. Eclipse的常用快捷键、旁门左道、系统错误小贴士
  5. JavaScript 页面跳转的几种方式 转
  6. \r,\n,\t
  7. identifier not found error on function call
  8. MySQL show status详解
  9. 修改Android中strings.xml文件, 动态改变数据
  10. Android自定义View之音频条形图
  11. Vijos 1002 过河 状态压缩DP
  12. scrapy---callback 传递自定义参数
  13. Hexo博客搭建
  14. 简单配置umiJS学习笔记
  15. swift 警告框 - 自定义按钮颜色,图片
  16. C++max的使用方法
  17. F. Ivan and Burgers(线性基,离线)
  18. Mac iTerm2登陆CentOS提示warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
  19. P1757 通天之分组背包 / hdu1712 ACboy needs your help (分组背包入门)
  20. 我和C语言程序

热门文章

  1. MVC5+EF6 入门完整教程3 :EF完整开发流程
  2. 只想remove parentNode的一部分children
  3. python UI自动化之切换iframe
  4. nginx配置访问黑名单-2
  5. Python 多任务(线程) day2 (2)
  6. ansible笔记(9):初识ansible playbook(二)
  7. awk从放弃到入门(1):awk基础
  8. git 提交的时候 建立排除文件夹或者文件
  9. 使用Id访问table对象,使用Id访问Input对象
  10. vue Cli 按需引入Element UI 和全局引用Element UI