首页 > 其他 > 详细

树的遍历——A1079.Total Sales of Supply Chain(25) 与A1090类似

时间:2020-01-26 20:52:11      阅读:69      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <queue>
using namespace std;
const int maxn = 100010;
struct node{
    double data;
    vector<int> child;
}Node[maxn];
int n;
double p,r,ans = 0;
void DFS(int index,int depth){
    if(Node[index].child.size() == 0){
        ans += Node[index].data * pow(1+r,depth);
        return;
    }else{
        for(int i = 0;i<Node[index].child.size();++i){
            DFS(Node[index].child[i],depth+1);
        }
    }
}
int main(){
    int k,child;
    scanf("%d%lf%lf",&n,&p,&r);
    r /= 100;
    for(int i=0;i<n;++i){
        scanf("%d",&k);
        if(k == 0){
            scanf("%lf",&Node[i].data);
        }else{
            for(int j =0;j<k;++j){
                scanf("%d",&child);
                Node[i].child.push_back(child);
            }
        }
    }
    DFS(0,0);
    printf("%.1f\n",ans * p);
    system("pause");
    return 0;
}

 

树的遍历——A1079.Total Sales of Supply Chain(25) 与A1090类似

原文:https://www.cnblogs.com/JasonPeng1/p/12234754.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!