uva12186 Another Crisis

A couple of years ago, a new world wide crisis started, leaving many
people with economical problems. Some workers of a particular company
are trying to ask for an increase in their salaries. The company has a
strict hierarchy, in which each employee has exactly one direct boss,
with the exception of the owner of the company that has no boss.
Employees that are not bosses of any other employee are called workers
. The rest of the employees and the owner are called bosses . To ask
for a salary increase, a worker should le a petition to his direct
boss. Of course, each boss is encouraged to try to make their
subordinates happy with their current income, making the company’s pro
t as high as possible. However, when at least T percent of its direct
subordinates have led a petition, that boss will be pressured and
have no choice but to le a petition himself to his own direct boss.
Each boss les at most 1 petition to his own direct boss, regardless
on how many of his subordinates led him a petition. A boss only
accounts his direct subordinates (the ones that led him a petition
and the ones that didn’t) to calculate the pressure percentage. Note
that a boss can have both workers and bosses as direct subordinates at
the same time. Such a boss may receive petitions from both kinds of
employees, and each direct subordinate, regardless of its kind, will
be accounted as 1 when checking the pressure percentage. When a
petition le gets all the way up to the owner of the company, all
salaries are increased. The workers’ union is desperately trying to
make that happen, so they need to convince many workers to le a
petition to their direct boss. Given the company’s hierarchy and the
parameter T , you have to nd out the minimum number of workers that
have to le a petition in order to make the owner receive a petition.
Input There are several test cases. The input for each test case is
given in exactly two lines. The rst line contains two integers N and
T (1 N 10 5 , 1 T 100), separated by a single space. N
indicates the number of employees of the company (not counting the
owner) and T is the parameter described above. Each of the employees
is identi ed by an integer between 1 and N . The owner is identi ed by
the number 0. The second line contains a list of integers separated by
single spaces. The integer B i , at position i on this list (starting
from 1), indicates the identi cation of the direct boss of employee i
(0 B i i

动态规划,用dp[i]表示让i写信需要请愿的最少人数,求解时把所有儿子的dp值排序去前若干个小的累加。

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> son[100010],choi[100010];
int n,T;
int dfs(int u)
{
    if (son[u].size()==0) return 1;
    int i,j,k,v,x,y,ret;
    x=son[u].size();
    for (i=0;i<x;i++)
      choi[u].push_back(dfs(son[u][i]));
    sort(choi[u].begin(),choi[u].end());
    if (x*T%100==0) y=x*T/100;
    else y=x*T/100+1;
    ret=0;
    for (i=0;i<y;i++)
      ret+=choi[u][i];
    return ret;
}
int main()
{
    int i,j,k,p,q,u,v,x,y,z;
    while (scanf("%d%d",&n,&T)&&n)
    {
        for (i=0;i<=n;i++)
          son[i].clear(),choi[i].clear();
        for (i=1;i<=n;i++)
        {
            scanf("%d",&x);
            son[x].push_back(i);
        }
        printf("%d\n",dfs(0));
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值