#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
int N;
double p,r;
struct node
{
vector<int> child;
};
node cube[100005];
int amount[100005]={0};
double ans=0;
void dfs(int id,int depth)
{
if(cube[id].child.size()==0)
{
ans+=p*pow(1+r/100,depth)*amount[id];
return;
}
for(int i=0;i<cube[id].child.size();i++)
{
dfs(cube[id].child[i],depth+1);
}
return;
}
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d %lf %lf",&N,&p,&r);
for(int i=0;i<N;i++)
{
int n;
scanf("%d",&n);
if(n==0)
{
int t;
scanf("%d",&t);
amount[i]=t;
}
else
{
for(int j=0;j<n;j++)
{
int t;
scanf("%d",&t);
cube[i].child.push_back(t);
}
}
}
dfs(0,0);
printf("%.1f",ans);
return 0;
}
1079. Total Sales of Supply Chain (25)--dfs
最新推荐文章于 2023-03-01 16:18:08 发布
本文介绍了一个使用C++实现的递归算法,用于遍历一个由节点组成的树形结构,并计算每个叶子节点的加权收益。该算法适用于金融、决策树等场景中的收益预测。


2181

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



