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

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > php教程 > [poj 3342]Party at Hali-Bula 樹形dp

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

來源:程序員人生   發(fā)布時間:2016-06-06 08:07:56 閱讀次數(shù):2826次

題目鏈接: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起參加。要求使參加人數(shù)最多,并要求判斷方案是不是唯1。

思路
計(jì)算最大的很簡單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;初始當(dāng)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])); } }
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 久久国产一级毛片一区二区 | 男女自偷自拍视频免费观看篇 | 高清不卡一区二区三区 | 精品亚洲在线 | 久久久久久国产精品免费免 | 武则天a级在线 | 一区二区中文字幕亚洲精品 | 宇都宫紫苑乳在线观看 | 福利视频美女国产精品 | 欧美黑人性受xxxx精品 | 夜夜操狠狠干 | 性欧美tubepornofree| 欧美性猛交xxx嘿人猛交 | 亚洲精品国产精品国自产网站 | 黄色小说区 | 中国性猛交xxxx乱大交 | 亚洲影院手机版777点击进入影院 | 久久桃色| 国产chinesehdxxxx大胸 | 日本一区二区三区不卡在线视频 | 日韩国产免费一区二区三区 | 精品国产一区二区二三区在线观看 | 最近最新的免费中文字幕 | 国产精品国产精品国产专区不卡 | 精品哟哟哟国产在线观看不卡 | 欧美一级淫片漂亮的老师 | 亚洲国产成人久久精品影视 | 大焦伊人 | 欧美区一区二区三 | 久久精品视频9 | 亚洲精品老司机在线观看 | 高清视频在线观看+免费 | 欧美一区二区久久精品 | 日韩欧美高清视频 | 色爱区综合| 欧美自拍偷拍视频 | 精品国产a | 国内高清久久久久久久久 | 欧美天天 | 久久亚洲一区二区 | 亚洲综合欧美日本另类激情 |