matter
DFS的作用:遍历整个树,求树的深度
code
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
const int MAXN = 100005;
double P , R , ans;
struct node{
int num;
vector<int> child;
}Node[MAXN];
void DFS(int root , int depth){
if(Node[root].child.size() == 0){
//price * number * (1 + r) ^ depth
ans += P * Node[root].num * pow(1 + R / 100 , depth);
return ;
}
for(int i = 0 ; i < Node[root].child.size() ; i ++){
DFS(Node[root].child[i] , depth + 1);
}
}
int main(){
int N ;
scanf("%d %lf %lf" , &N , &P , &R);
//input
for(int i = 0 ; i < N ; i ++){
int n;
scanf("%d" , &n);
if(n == 0){
scanf("%d" , &Node[i].num);
}
else{
for(int j = 0 ; j < n ; j ++){
int k;
scanf("%d" , &k);
Node[i].child.push_back(k);
}
}
}
//DFS
DFS(0 , 0);
//output
printf("%.1f" , ans);
return 0;
}