日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > [poj 3342]Party at Hali-Bula 樹形dp

[poj 3342]Party at Hali-Bula 樹形dp

來源:程序員人生   發布時間:2016-06-06 08:07:56 閱讀次數:2831次

題目鏈接:http://poj.org/problem?id=3342
Party at Hali-Bula

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 5997 Accepted: 2140

Description

Dear Contestant,

I’m going to have a party at my villa at Hali-Bula to celebrate my retirement from BCM. I wish I could invite all my co-workers, but imagine how an employee can enjoy a party when he finds his boss among the guests! So, I decide not to invite both an employee and his/her boss. The organizational hierarchy at BCM is such that nobody has more than one boss, and there is one and only one employee with no boss at all (the Big Boss)! Can I ask you to please write a program to determine the maximum number of guests so that no employee is invited when his/her boss is invited too? I’ve attached the list of employees and the organizational hierarchy of BCM.

Best,
–Brian Bennett

P.S. I would be very grateful if your program can indicate whether the list of people is uniquely determined if I choose to invite the maximum number of guests with that condition.

Input

The input consists of multiple test cases. Each test case is started with a line containing an integer n (1 ≤ n ≤ 200), the number of BCM employees. The next line contains the name of the Big Boss only. Each of the following n⑴ lines contains the name of an employee together with the name of his/her boss. All names are strings of at least one and at most 100 letters and are separated by blanks. The last line of each test case contains a single 0.

Output

For each test case, write a single line containing a number indicating the maximum number of guests that can be invited according to the required condition, and a word Yes or No, depending on whether the list of guests is unique in that case.

Sample Input
6
Jason
Jack Jason
Joe Jack
Jill Jason
John Jack
Jim Jill
2
Ming
Cho Ming
0

Sample Output
4 Yes
1 No

Source

Tehran 2006

題意:BB將要約請BCM的員工參加1個party來慶祝他的退休。還是每一個人不能同其直接boss1起參加。要求使參加人數最多,并要求判斷方案是不是唯1。

思路
計算最大的很簡單dp[i][0]=求和max(dp[soni][0],dp[soni][1]); dp[i][1]=求和dp[soni][0];

判斷開始只傻逼的判dp[1][0]=?dp[1][1];
利用flag[i][0]判斷,如果選的子樹方案不唯1,該方案不唯1;初始當dp[soni][0]==dp[soni][1]時flag【i】[0]=1;

代碼

#include<iostream> #include<stdio.h> #include<string.h> #include<map> #include<vector> using namespace std; int n; int tot; vector<int> lin[205]; map<string,int> q; string s,s1; int dp[201][2]; int flag[201][2]; void dfs(int x) { int ret=0; int tmp=0; int f1=0; int f2=0; for(int i=0;i<lin[x].size();i++) { int v=lin[x][i]; dfs(v); ret+=max(dp[v][0],dp[v][1]); if(dp[v][0]==dp[v][1]) f1=1; else if(dp[v][0]>dp[v][1]&&flag[v][0]==1) f1=1; else if(dp[v][1]>dp[v][0]&&flag[v][1]==1) f1=1; tmp+=dp[v][0]; if(flag[v][0]) f2=1; } dp[x][0]=ret; dp[x][1]=tmp+1; if(f2) flag[x][1]=1; if(f1) flag[x][0]=1; } int main() { while(scanf("%d",&n)) { if(!n) return 0; tot=0; cin>>s; q.clear(); q[s]=++tot; for(int i=1;i<=n;i++) { lin[i].clear(); } for(int i=1;i<n;i++) { cin>>s>>s1; if(!q[s]) { q[s]=++tot; } if(!q[s1]) { q[s1]=++tot; } lin[q[s1]].push_back(q[s]); } memset(flag,0,sizeof(flag)); memset(dp,0,sizeof(dp)); dfs(1); if(dp[1][0]==dp[1][1]) { printf("%d No\n",dp[1][0]); } else if(dp[1][0]>dp[1][1]&&flag[1][0]) { printf("%d No\n",dp[1][0]); } else if(dp[1][1]>dp[1][0]&&flag[1][1]) { printf("%d No\n",dp[1][1]); } else printf("%d Yes\n",max(dp[1][0],dp[1][1])); } }
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲综合在线视频 | 国产一区二区在线视频播放 | 三级av毛片 | 91麻豆精品国产自产在线观看一区 | 黄色大片区| 91精品国产综合久久久久蜜臀 | 精品一区二区三区在线观看国产 | 国内久久精品 | 99精品国产成人一区二区 | 国产精品视频一区二区三区四 | 久久久国产一区 | 亚洲一区二区中文字幕 | 日韩欧美国产精品 | 国产一区二区毛片 | 国产精品视频一二三四区 | 国产不卡在线播放 | 日韩欧美片 | 亚洲国产精品久久久久 | 国产精品卡一卡二 | 久久综合久久久 | 亚洲一二三区在线 | 国产精品永久 | 草久久| 在线播放国产精品 | 国产黄一级 | 日日爽 | 国产一区二区在线看 | 午夜噜噜噜 | 亚洲黄色影院 | 久热导航 | 国产视频一区在线播放 | 日本一二三区视频在线 | 国产精品二区三区 | av在线成人 | 国产香蕉视频在线 | 97av视频| 国产性一级片 | 精品一区二区三区在线观看国产 | 欧美精品在线观看 | 国产精品久久久久久久久久小说 | 日韩国产欧美综合 |