1106 Lowest Price in Supply Chain(25 分)

#include 
#include 
#include 
#include
#include
#include
using namespace std;
#define STP system("pause")

vector>v;
int mindepth=9999;

multisets;

void dfs(int index,int depth)
{
    if (v[index].empty())//如果没有下级则代表是零售商
    {
        //cout << "depth=" << depth << endl;
        mindepth = min(mindepth, depth);
        s.insert(depth);
        return;
    }
    for (int j = 0; j < v[index].size(); j++)
    {
        //cout << v[index][j];
        ++depth;
        dfs(v[index][j],depth);//每进去一层则加一,退出一层则减一
        depth--;
    }
    return;
}

int main()
{
    int M,N,index;
    double P, r;
    cin >> M>>P>>r;
    

    for (int i = 0; i < M; i++)
    {
        cin >> N;
        vector vi;
        for (int j = 0; j < N; j++)
        {
            cin >> index;
            vi.push_back(index);
        }
        v.push_back(vi);
    }

    dfs(0,0);

    cout << setiosflags(ios::fixed) << setprecision(4) << P * pow((1.00 + 0.01*r), mindepth) << " ";
    cout << s.count(*(s.begin())) << endl;;
    //cout<< mindepth << endl;
    STP;
    return 0;
}

你可能感兴趣的:(1106 Lowest Price in Supply Chain(25 分))