【codechef】Singal Pipes(DFS求期望)
2015-09-03 20:17
417 查看
https://www.codechef.com/IOPC2015/problems/IOPC15L
#include <bits/stdc++.h> using namespace std; #define sd(x) scanf("%d",&x) vector<int> graph[200]; int parents[200]; double color[200][200]; void DFS(int root,int b,double add){ for(int i=0;i<graph[root].size();i++){ color[graph[root][i]][b]+=add/parents[graph[root][i]]; DFS(graph[root][i],b,add/parents[graph[root][i]]); } } int main(){ int t,c,m,n,p,x,y,b; sd(t); while(t--){ sd(c);sd(p); for(int i=0;i<c;i++)graph[i].clear(); memset(parents,0,sizeof(int)*200); while(p--){ sd(x);sd(y); x--;y--; graph[y].push_back(x); parents[x]++; } sd(m);sd(n); memset(color,0,sizeof(double)*40000); while(m--){ sd(x);sd(b); x--;b--; color[x][b]=1; DFS(x,b,1); } for(int i=0;i<n;i++){ double total=0; for(int j=0;j<c;j++)total+=color[j][i]; printf("%lf ",total); } cout<<endl; } return 0; }
相关文章推荐
- 实现iOS 8 Safari可伸缩的NavigationBar
- 1.2 二分法
- Java中多线程重复启动
- UVa 10723 LCS变形 Cyborg Genes
- Ruby on Rails Guides(一)
- hdu 5417 Victor and Machine
- Nginx中如何限制某个IP同一时间段的访问次数
- 文件查找命令 whereis locate find
- Linux套接字与虚拟文件系统(1):初始化和创建 http://www.cppblog.com/qinqing1984/archive/2015/05/03/210521.html
- 使用Ajax加载数据的dataTables
- 20150902 Java学习笔记-构造方法,关键字,封装性
- shutdown immediate 卡在SMON: disabling tx recovery
- 树的重心 树形DP SGU 134
- C++模板元编程 - 3 逻辑结构,递归,一点列表的零碎,一点SFINAE
- hdoj 4686 Arc of Dream 【矩阵快速幂】
- 如何写memset函数
- GCD的基本使用
- mysql防止重复插入相同记录 insert if not exists
- Codeforces Round #311 (Div. 2)
- CCF认证题 搜索题