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;
}
本文介绍了如何使用C++编程语言解决一个特定的竞赛问题,该问题涉及到树形动态规划(Tree DP)和深度优先搜索(DFS)算法。通过详细解释算法思路和代码实现,作者提供了解决类似问题的实用技巧和步骤,帮助读者理解和掌握树形DP和DFS在实际编程中的应用。
5473

被折叠的 条评论
为什么被折叠?



