PAT A1079 Total Sales of Supply Chain(关于树的遍历)

Posted jicheng1996

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT A1079 Total Sales of Supply Chain(关于树的遍历)相关的知识,希望对你有一定的参考价值。

DFS遍历

#include<cstdio>

#include<cmath>

using name spacestd;

const int maxn=10012;

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;

}

for (int i=0;i<Node[index].child.size();i++){

DFS(Node[index].child[i],depth+1);

}}

int main(){

int x,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("%.lf‘ ",p*ans);

return 0;

}

 

以上是关于PAT A1079 Total Sales of Supply Chain(关于树的遍历)的主要内容,如果未能解决你的问题,请参考以下文章

PAT 1079 Total Sales of Supply Chain[比较]

PAT甲级--Total Sales of Supply Chain (25)

PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)

PAT Advanced 1079 Total Sales of Supply Chain (25) [DFS,BFS,树的遍历]

PAT甲级1079 Total Sales of Supply Chain (25 分)

1079 total sales of supply chain