zoukankan      html  css  js  c++  java
  • UVA12186

    给出一个树状关系图,公司里只有一个老板编号为0,其他人员从1开始编号。除了老板,每个人都有一个直接上司,没有下属的员工成为工人。

    工人们想写一份加工资的请愿书,只有当不少于员工的所有下属的T%人递交请愿书后,该员工才会将请愿书递交给他的直接上级。输出能递交到老板处,最少需要多少工人写请愿书         

    算法入门中树形动归的例题(学习中)

     temp = (k * T - 1)/100 + 1; 判断最少需要的人数


    #include <iostream>
    #include <vector>
    #include <cstring>
    #include <cstdio>
    #include <queue>
    #include <algorithm>
    using namespace std;
    vector<int>qu[100005];
    int n,T;
    
    int dp(int u)
    {
        if(qu[u].empty())
            return 1;
    
        int k = qu[u].size();
        vector<int>d;
        for(int i = 0; i < k; i++)
            d.push_back(dp(qu[u][i]));
    
        int temp = (k * T - 1)/100 + 1;
        sort(d.begin(),d.end());
        int ans = 0;
        for(int i = 0;i < temp;i++) ans+= d[i];
        return ans;
    }
    
    int main()
    {
        while(scanf("%d%d",&n,&T))
        {
            if(!n && !T)
                break;
    
            for(int i = 0; i <= n; i++)
                qu[i].clear();
    
    
            for(int i = 1; i <= n; i++)
            {
                int x;
                scanf("%d",&x);
                qu[x].push_back(i);
            }
            printf("%d
    ",dp(0));
        }
        return 0;
    }
    

      

  • 相关阅读:
    稠密光流
    分水岭分割
    Haar小波分析
    内积空间
    矩阵LU分解
    opencv笔记---contours
    Deformable Templates For Eye Detection
    最小二乘法
    字符集及编码
    层次聚类
  • 原文地址:https://www.cnblogs.com/Przz/p/5409830.html
Copyright © 2011-2022 走看看