您的位置:首页 > 其它

【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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: