• 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;
    }
    

      

  • 相关阅读:
    教你在mac上配置adb环境变量
    Android Mediaplayer 调用release()的时候ANR
    Android ANR
    安卓android WebView Memory Leak WebView内存泄漏
    android 小结
    struts提供文件上传功能
    struts自定义拦截器
    struts拦截器的配置和使用
    Struts框架属性驱动
    struts配置文件
  • 原文地址:https://www.cnblogs.com/Przz/p/5409830.html
Copyright © 2020-2023  润新知