博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 3342 Party at Hali-Bula(树形DP+判断方式是不是唯一)
阅读量:4036 次
发布时间:2019-05-24

本文共 2633 字,大约阅读时间需要 8 分钟。

1、

2、题目大意:

现在要邀请n个人中的一些人参加晚宴,要求是有直接上下级关系的人不能同时出席,问最多可以邀请多少人参加,并判断在保证最大人数的情况下,人是不是唯一确定的

状态转移方程很好确定,难在怎么判断方案是不是唯一,假设第i个人参加时值最大,那么不能确定是不是不唯一,但是如果第i个人不去的方案最优的话,他的状态有两种,孩子要么去,要么不去,如果这两种状态的最大值相同,那么就是不唯一的,详见代码

3、题目:

Party at Hali-Bula
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 4917   Accepted: 1741

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 integern (1 ≤ n ≤ 200), the number of BCM employees. The next line contains the name of the Big Boss only. Each of the followingn-1 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

6JasonJack JasonJoe JackJill JasonJohn JackJim Jill2MingCho Ming0

Sample Output

4 Yes1 No

 

4、AC代码:

#include
#include
#include
#include
#include
#include
using namespace std;vector
vec[205];map
mp;char str[205][105];char tmp[105];char a[105],b[105];int dp[205][2];int k;int find(char a[105]){ for(int i=0; i
dp[i][1]) { for(int j=0; j

5、AC代码,处理字符串用的for循环遍历的,没有用map

 

#include
#include
#include
using namespace std;vector
vec[205];char str[205][105];char tmp[105];char tmp1[105];int dp[205][2];int k;int find(char a[105]){ for(int i=0; i
=dp[i][1]) { for(int j=0; j

 

 

转载地址:http://ehddi.baihongyu.com/

你可能感兴趣的文章
Java的初始化机制、垃圾回收机制和内存分配机制
查看>>
MySQL5.6安装步骤(windows7/8_64位)
查看>>
FreeMarker基础配置
查看>>
Java中使用Jedis操作Redis
查看>>
Redis中常用命令
查看>>
spring下载
查看>>
读取request流
查看>>
微信消息模板的配置
查看>>
Spring框架结合Quartz实现任务调度实例
查看>>
Quartz Cron表达式 在线生成器
查看>>
struts2中action接收参数的3种方法
查看>>
java获取随机数
查看>>
url中传递中文参数时的转码与解码
查看>>
百度Ueditor设置允许上传的图片格式及大小
查看>>
java图形验证码生成工具类及web页面校验验证码
查看>>
微信菜单的配置
查看>>
移动端的emoji表情符号插入MySQL数据库失败
查看>>
mysql对指定列进行排名
查看>>
Eclipse安装FindBugs插件
查看>>
联想T440怎么把原装Win8或Win10换成Win7系统
查看>>