多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當前位置:首頁 > php開源 > php教程 > UVA 12186 Another Crisis(樹形DP)

UVA 12186 Another Crisis(樹形DP)

來源:程序員人生   發(fā)布時間:2014-12-07 09:39:09 閱讀次數(shù):3559次

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());//選擇子數(shù)中代價最小的 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; }


生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 复仇之路在线观看免费版高清 | 精品久久久久不卡无毒 | free性欧洲69| 在线看逼 | 国产中文字幕在线播放 | 一区二区三区四区国产精品 | 国产丰满主播丝袜勾搭秀 | 亚洲欧美另类视频 | 一区二区三区欧美 | 爰上碰23在线视频 | 都市激情亚洲色图 | 亚洲欧美视频在线观看 | 天堂在线观看视频 | 午夜三级在线 | 美女教师一级毛片 | 国产精品成aⅴ人片在线观看 | 全国男人的天堂网站 | 亚洲精品乱码久久久久久 | 亚洲成年人在线 | 欧美一区精品二区三区 | 久久视频精品53在线观看 | 欧美激情亚洲精品日韩1区2区 | 日本xxxwww在线观看免费 | 久久www免费人成看国产片 | 最近高清中文字幕在线国语5 | 欧美黑人巨大videos异族 | 亚洲毛片在线看 | 欧美成人一区二区三区在线视频 | 亚洲夜夜爽 | 九九99久久精品在免费线bt | 一区二区不卡在线 | 视频在线观看网站免费 | 成人私拍福利视频在线 | 在线观看成年人免费视频 | 欧美一区二区三区精品国产 | 日韩欧美高清 | 91在线精品亚洲一区二区 | 色老头福影院韩国激情影院 | 日本护士高清xxxxx | 最新国产在线观看福利91 | 波多野结中文字幕在线69视频 |