-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA1079.cpp
62 lines (43 loc) · 897 Bytes
/
A1079.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
const int maxn = 100010;
struct node{
double data; //货物量
vector<int> child; //指针域
}Node[maxn];
int n;
double p, r, ans = 0;
//用递归实现DFS, 注意二点。1.递归式 2.递归边界
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 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.child.push_back(child);
}
}
}
DFS(0, 0);
printf("%.lf\n", p*ans);
return 0;
}