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
91 0
|
存储 Python
LeetCode 315. Count of Smaller Numbers After Self
给定一个整数数组 nums,按要求返回一个新数组 counts。数组 counts 有该性质: counts[i] 的值是 nums[i] 右侧小于 nums[i] 的元素的数量。
94 0
LeetCode 315. Count of Smaller Numbers After Self
LeetCode 152. Maximum Product Subarray
给定一个整数数组 nums ,找出一个序列中乘积最大的连续子序列(该序列至少包含一个数)。
47 0
LeetCode 152. Maximum Product Subarray
|
XML 数据格式
XML问题: The processing instruction target matching &quot;[xX][mM][lL]&quot; is not allowed
XML问题: The processing instruction target matching &quot;[xX][mM][lL]&quot; is not allowed
199 0
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
102 0
|
供应链
PAT (Advanced Level) Practice - 1079 Total Sales of Supply Chain(25 分)
PAT (Advanced Level) Practice - 1079 Total Sales of Supply Chain(25 分)
139 0
Leetcode-Medium 416. Partition Equal Subset Sum
Leetcode-Medium 416. Partition Equal Subset Sum
121 0
【1106】Lowest Price in Supply Chain (25 分)
【1106】Lowest Price in Supply Chain (25 分) 【1106】Lowest Price in Supply Chain (25 分)
94 0
【1090】Highest Price in Supply Chain (25 分)
【1090】Highest Price in Supply Chain (25 分) 【1090】Highest Price in Supply Chain (25 分)
99 0
下一篇
无影云桌面