其他分享
首页 > 其他分享> > 供应链总销售额

供应链总销售额

作者:互联网

https://www.acwing.com/problem/content/description/1567/

思路:
这题可以不用记忆化搜索写,也不是很烦,在这儿记忆化搜索主要是用来解决求树的深度用的。

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 100010;

int n;
double P, R;
int p[N], f[N], c[N];

int dfs(int u)
{
    if (f[u] != -1) return f[u];

    if (p[u] == -1) return f[u] = 0;
    return f[u] = dfs(p[u]) + 1;
}

int main()
{
    cin >> n >> P >> R;

    memset(p, -1, sizeof p);
    for (int i = 0; i < n; i ++ )
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j ++ )
        {
            int son;
            cin >> son;
            p[son] = i;
        }

        if (!k) cin >> c[i];
    }

    memset(f, -1, sizeof f);

    double res = 0;
    for (int i = 0; i < n; i ++ )
        if (c[i])
            res += c[i] * P * pow(1 + R / 100, dfs(i));

    printf("%.1lf\n", res);

    return 0;
}

标签:return,int,res,cin,son,供应链,销售额,include
来源: https://www.cnblogs.com/xjtfate/p/16603281.html