最新公告
  • 欢迎您光临波比源码,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入我们
  • UVA 12186 Another Crisis(树形DP)

    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 calledworkers.
    The rest of the employees and the owner are called bosses.

    To ask for a salary increase, a worker should file 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 profit
    as high as possible. However, when at least T percent of its direct subordinates have filed a petition, that boss will be pressured and have no choice but to file a petition himself to his own direct boss. Each boss files
    at most 1 petition to his own direct boss, regardless on how many of his subordinates filed him a petition. A boss only accounts his direct subordinates (the ones that filed 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 file 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 file a petition
    to their direct boss.

    Given the company’s hierarchy and the parameter T, you have to find out the minimum number of workers that have to file 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 first line contains two integers N and T ( 1$ le$N$ le$105 , 1$ le$T$ le$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 identified by an
    integer between 1 and N. The owner is identified by the number 0. The second line contains a list of integers separated by single spaces. The integer Bi, at position i on
    this list (starting from 1), indicates the identification of the direct boss of employee i (0$ le$Bi$ le$i –
    1)
    .

    The last test case is followed by a line containing two zeros separated by a single space.

    Output 

    For each test case output a single line containing a single integer with the minimum number of workers that need to file a petition in order to get the owner of the company to receive a petition.

    Sample Input 

    3 100 
    0 0 0 
    3 50 
    0 0 0 
    14 60 
    0 0 1 1 2 2 2 5 7 5 7 5 7 5 
    0 0
    

    Sample Output 

    3 
    2 
    

    5

    简单的树形DP:

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> typedef long long LL; using namespace std; #define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i ) #define REP( i , n ) for ( int i = 0 ; i < n ; ++ i ) #define CLEAR( a , x ) memset ( a , x , sizeof a ) const int maxn=1e5+100; vector<int>v[maxn]; int dp[maxn]; int n,t; int dfs(int x) { if(v[x].empty()) return 1; vector<int>num; int k=v[x].size(); for(int i=0;i<k;i++) num.push_back(dfs(v[x][i])); int c=(t*k⑴)/100+1; sort(num.begin(),num.end());//选择子数中代价最小的 int ans=0; for(int i=0;i<c;i++) ans+=num[i]; return ans; } int main() { int x; std::ios::sync_with_stdio(false); while(cin>>n>>t&&(n+t)) { CLEAR(dp,0); REPF(i,0,n) v[i].clear(); REPF(i,1,n) { cin>>x; v[x].push_back(i); } printf("%d ",dfs(0)); } return 0; }


    波比源码 – 精品源码模版分享 | www.bobi11.com
    1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
    2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
    3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
    4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
    5. 如有链接无法下载、失效或广告,请联系管理员处理!
    6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
    7. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

    波比源码 » UVA 12186 Another Crisis(树形DP)

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    波比源码
    一个高级程序员模板开发平台
    升级波友尊享更多特权立即升级