1106. Lowest Price in Supply Chain (25) dfs

简介: #include #include #include using namespace std;int n, mindepth = 9999999, minnum = 0;double p, r;vector v...
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int n, mindepth = 9999999, minnum = 0;
double p, r;
vector<int> v[100001];

void dfs(int index, int depth){
    if (depth > mindepth) return;
    if (v[index].size() == 0) {
        if (mindepth == depth) {
            minnum++;
        }else if(depth < mindepth){
            mindepth = depth;
            minnum = 1;
        }
    }
    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;
        for (int j = 0; j < c; j++) {
            int k;
            cin >> k;
            v[i].push_back(k);
        }
    }
    dfs(0, 0);
    
    printf("%.4lf %d\n", p * pow(1 + r/100, mindepth), minnum);
    
    return 0;
}

目录
相关文章
|
存储 供应链 C++
【PAT甲级 - C++题解】1106 Lowest Price in Supply Chain
【PAT甲级 - C++题解】1106 Lowest Price in Supply Chain
79 0
|
存储 供应链 C++
【PAT甲级 - C++题解】1079 Total Sales of Supply Chain
【PAT甲级 - C++题解】1079 Total Sales of Supply Chain
89 0
LeetCode 152. Maximum Product Subarray
给定一个整数数组 nums ,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数)。
46 0
LeetCode 152. Maximum Product Subarray
Neither Quantity object nor its magnitude supports indexing
Neither Quantity object nor its magnitude supports indexing
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
101 0
|
供应链
PAT (Advanced Level) Practice - 1079 Total Sales of Supply Chain(25 分)
PAT (Advanced Level) Practice - 1079 Total Sales of Supply Chain(25 分)
138 0
【1106】Lowest Price in Supply Chain (25 分)
【1106】Lowest Price in Supply Chain (25 分) 【1106】Lowest Price in Supply Chain (25 分)
93 0
【1090】Highest Price in Supply Chain (25 分)
【1090】Highest Price in Supply Chain (25 分) 【1090】Highest Price in Supply Chain (25 分)
97 0
【1079】Total Sales of Supply Chain (25 分)
【1079】Total Sales of Supply Chain (25 分) 【1079】Total Sales of Supply Chain (25 分)
117 0
1090. Highest Price in Supply Chain (25) dfs
#include #include #include using namespace std; int n, maxnum, maxdepth = 0, root = 0; double p, r; vector ...
936 0