hdu 2412 Party at Hali-Bula 经典树形DP
Party at Hali-Bula
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1365 Accepted Submission(s): 454
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.
Jason
Jack Jason
Joe Jack
Jill Jason
John Jack
Jim Jill
2
Ming
Cho Ming
0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std; struct node
{
int next[];
int num;
}f[];
char cur[][];
int len;
bool glag,flag;
int dp[][];
int ndp[][]; int Max(int x,int y)
{
return x>y? x:y;
} int serch(char a[])
{
int i;
for(i=;i<=len;i++)
{
if(strcmp(a,cur[i])==)
return i;
}
strcpy(cur[++len],a);
return len;
} void dfs(int k)
{
int i,q,cur=;
if(f[k].num==)
{
dp[k][]=;
dp[k][]=;
ndp[k][]=;
ndp[k][]=;
return;
}
for(i=;i<=f[k].num;i++)
{
q=f[k].next[i];
dfs(q);
cur=Max(dp[q][],dp[q][]);
dp[k][]+=cur;
dp[k][]+=dp[q][]; if(dp[q][]>dp[q][]&&ndp[q][]==)
ndp[k][]=;
if(dp[q][]>dp[q][]&&ndp[q][]==)
ndp[k][]=;
if(dp[q][]==dp[q][]) ndp[k][]=; if(ndp[q][]==) ndp[k][]=;
}
dp[k][]++;
if(ndp[k][]==-) ndp[k][]=;
if(ndp[k][]==-) ndp[k][]=;
} int main()
{
int i,n,ans1,ans2;
char a[],b[];
while(scanf("%d",&n)>)
{
if(n==)break;
for(i=;i<=;i++) f[i].num=;
scanf("%s",cur[]);
len=;
for(i=;i<n;i++)
{
scanf("%s%s",a,b);
ans1=serch(a);
ans2=serch(b); f[ans2].num++;
f[ans2].next[f[ans2].num]=ans1; }
memset(dp,,sizeof(dp));
memset(ndp,-,sizeof(ndp));
glag=false;flag=false;
dfs(); if(dp[][]>dp[][]&&ndp[][]==)
printf("%d Yes\n",dp[][]);
else if(dp[][]>dp[][]&&ndp[][]==)
printf("%d Yes\n",dp[][]);
else printf("%d No\n",Max(dp[][],dp[][]));
}
return ;
}
hdu 2412 Party at Hali-Bula 经典树形DP的更多相关文章
- HDU 1561 The more, The Better 经典树形DP
The more, The Better Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 4126 Genghis Khan the Conqueror 最小生成树+树形dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4126 Genghis Khan the Conqueror Time Limit: 10000/50 ...
- hdu 5909 Tree Cutting——点分治(树形DP转为序列DP)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5909 点分治的话,每次要做一次树形DP:但时间应该是 siz*m2 的.可以用 FWT 变成 siz*ml ...
- hdu 1520 Anniversary party(第一道树形dp)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Time Limit: 2000/1000 MS (Java ...
- bzoj 2159 Crash 的文明世界 && hdu 4625 JZPTREE ——第二类斯特林数+树形DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2159 学习材料:https://blog.csdn.net/litble/article/d ...
- bzoj 2159 Crash 的文明世界 & hdu 4625 JZPTREE —— 第二类斯特林数+树形DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2159 使用公式:\( n^{k} = \sum\limits_{i=0}^{k} S(k,i ...
- HDU 4003 Find Metal Mineral(分组背包+树形DP)
题目链接 很棒的一个树形DP.学的太渣了. #include <cstdio> #include <string> #include <cstring> #incl ...
- 【HDU - 4340】Capturing a country(树形DP)
BUPT2017 wintertraining(15) #8A 题意 n(<100)个城市组成的树.A攻击i城市需要a[i]代价,B需要b[i].如果一个城市的邻居被A攻击了,那么A攻击它只要A ...
- hdu 3660 Alice and Bob's Trip(树形DP)
Alice and Bob's Trip Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 1561 The more, The Better【树形DP/有依赖的分组背包】
ACboy很喜欢玩一种战略游戏,在一个地图上,有N座城堡,每座城堡都有一定的宝物,在每次游戏中ACboy允许攻克M个城堡并获得里面的宝物.但由于地理位置原因,有些城堡不能直接攻克,要攻克这些城堡必须先 ...
随机推荐
- idea 新建New Module时Maven的列表加载不出来
Under Build → Build Tools → Maven → Importing, set VM options for importer to -Xmx1024m (the default ...
- PHP消息队列实现
一个经典的消息队列就是这样的,主要是入队出队操作. shell脚本日志输出 学习地址:http://www.imooc.com/article/19111
- [CISCO] 思科交换机基本配置
思科交换机基本配置 交换机是局域网中最重要的设备,交换机是基于 MAC 来进行工作的.和路由器类似,交换 机也有 IOS,IOS 的基本使用方法是一样的.本章将简单介绍交换机的一些基本配置,以及交换 ...
- JSP里面九个内置对象
JSP内置对象(9个常用的内置对象) 1.request对象 客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求, 然后做出响应.它是HttpServletRequest类的实例 ...
- Dota2App--第三天
一.要实现的功能 1.新特性页面 1.1.是否进入新特性界面的两种情况 1)第一次安装此APP,进入新特性界面 2)不是第一次安装,但是有版本更新,进入新特性界面 1.2.具体的代码实现 //0.版本 ...
- Vultr VPS建站攻略 – 一键安装宝塔面板架设LNMP/LAMP Web环境
我们选择VULTR VPS建站的还是比较多的,其主要原因在于商家的稳定,毕竟我们用来建站选择服务器价格考虑的不是主要的(当然VULTR价格也是比较便宜),最为主要的是因为VULTR商家比较稳定,而且多 ...
- ui2-3
2016.9讲义 一.课程的主要内容和目的 二.课程所用工具软件——Photoshop CS6 1. Photoshop 的发展史 1990.2,ps1.0问世,1991.2,PS2.0发行,此后,进 ...
- Microsoft Power BI Desktop概念学习系列之Microsoft Power BI Desktop的官网自带示例数据(图文详解)
不多说,直接上干货! https://docs.microsoft.com/zh-cn/power-bi/sample-datasets 后续的博文系列,将进行深入的剖析和分享. 欢迎大家,加入我的微 ...
- Tomcat *的安装和运行(绿色版和安装版都适用)
不多说,直接上干货! 前提, Tomcat *的下载(绿色版和安装版都适用) 一.Tomcat的安装版 1.新建安装目录 2.放置安装版的tomcat 3.双击 4.点击 I agree 5.选择“F ...
- ServiceLoader解读
SPI的全名为Service Provider Interface.普通开发人员可能不熟悉,因为这个是针对厂商或者插件的.在java.util.ServiceLoader的文档里有比较详细的介绍. 简 ...