1079. Total Sales of Supply Chain (25) dfs

简介: #include #include #include #include using namespace std;vector v[100001];vector amount[100001];int n;d...
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

vector<int> v[100001];
vector<int> amount[100001];
int n;
double sum = 0, p, r;

void dfs(int index, int depth){
    if (v[index].size() == 1 && v[index][0] == -1) {
        sum += pow(1 + r/100, depth) * amount[index][0];
        return;
    }
    for (int i = 0; i < v[index].size(); i++) {
        dfs(v[index][i], depth + 1);
    }
}

int main(){
    cin >> n >> p >> r;
    for (int i = 0; i < n; i++) {
        int c;
        cin >> c;
        if (c == 0) {
            v[i].push_back(-1);
            int k;
            cin >> k;
            amount[i].push_back(k);
        }else{
            for (int j = 0; j < c; j++) {
                int k;
                cin >> k;
                v[i].push_back(k);
            }
        }
    }
    dfs(0, 0);
    printf("%.1lf\n", sum * p);
    return 0;
}

目录
相关文章
|
8月前
|
调度 索引
NR PUCCH(四) UL data operation
UE 在connected mode 需要实时和网络进行上下行通信,在UE有UL data要发送但是没有UL grant时,就需要向网络端发送SR请求资源,网络收到SR就会在激活的BWP上发送 UL DCI给UE,UE 根据UL DCI 信息 获得UL grant ,然后在PUSCH对应的资源上就可以发送UL data给网络,最后网络端通过HARQ 过程指示是否有收到对应的data。这是UL data 的基本流程,下面通过实际log分别看下UL data operation的各个过程。
|
10月前
|
存储 供应链 C++
【PAT甲级 - C++题解】1079 Total Sales of Supply Chain
【PAT甲级 - C++题解】1079 Total Sales of Supply Chain
71 0
|
10月前
|
存储 供应链 C++
【PAT甲级 - C++题解】1106 Lowest Price in Supply Chain
【PAT甲级 - C++题解】1106 Lowest Price in Supply Chain
54 0
|
人工智能
Tree with Maximum Cost---CF1092F 树上DP
You are given a tree consisting exactly of n vertices. Tree is a connected undirected graph with n−1 edges. Each vertex v of this tree has a value av assigned to it. Let dist(x,y) be the distance between the vertices x and y.
118 0
Tree with Maximum Cost---CF1092F 树上DP
|
供应链
PAT (Advanced Level) Practice - 1079 Total Sales of Supply Chain(25 分)
PAT (Advanced Level) Practice - 1079 Total Sales of Supply Chain(25 分)
117 0
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
84 0
【1079】Total Sales of Supply Chain (25 分)
【1079】Total Sales of Supply Chain (25 分) 【1079】Total Sales of Supply Chain (25 分)
98 0
【1106】Lowest Price in Supply Chain (25 分)
【1106】Lowest Price in Supply Chain (25 分) 【1106】Lowest Price in Supply Chain (25 分)
73 0
【1090】Highest Price in Supply Chain (25 分)
【1090】Highest Price in Supply Chain (25 分) 【1090】Highest Price in Supply Chain (25 分)
77 0
why My Lead OPA test add Lead fails
why My Lead OPA test add Lead fails
104 0
why My Lead OPA test add Lead fails