题目

PAT A1079 Total Sales of Supply Chain (25 point(s))
PAT A1079 Total Sales of Supply Chain (25 point(s))

Code

#include
#include
#include
#include
using namespace std;
const int maxn=100100;
struct node{
double data;
vector child;
}Node[maxn];
int n;
double p,r,ans=0;
void DFS(int index,int depth){
if(Node[index].child.size()==0){// leaf 临界条件
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 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",p*ans);
return 0;

}

相关文章:

  • 2022-12-23
  • 2021-04-26
  • 2021-12-18
  • 2022-12-23
  • 2021-12-09
  • 2021-10-05
  • 2021-12-15
  • 2021-06-17
猜你喜欢
  • 2021-11-02
  • 2021-07-05
  • 2021-10-10
  • 2022-03-09
  • 2021-06-09
  • 2022-01-21
相关资源
相似解决方案