博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1520 Anniversary party(基本树形DP)
阅读量:4035 次
发布时间:2019-05-24

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

1、

2、题目大意:

有n个员工,每个员工都有一个rating值,给出员工之间的上下级的关系,要求是有直接上下级关系的员工不能同时出席,现在要求的是选择哪些员工出席,会使得他们的rating之和最大

定义dp[i][1]表示i员工出席时的最大值,dp[i][0]表示i员工不出席时的最大值

dp[i][1]=dp[v][0]//当i员工出席时,就等于他的所有直接下属v不出席时的最大值

dp[i][0]=max(dp[v][1],dp[v][0])//当i员工不出席时,就等于他的下属出席或者不出席的最大值

3、题目:

Anniversary party

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 3617    Accepted Submission(s): 1680

Problem Description
There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure of employees. It means that the supervisor relation forms a tree rooted at the rector V. E. Tretyakov. In order to make the party funny for every one, the rector does not want both an employee and his or her immediate supervisor to be present. The personnel office has evaluated conviviality of each employee, so everyone has some number (rating) attached to him or her. Your task is to make a list of guests with the maximal possible sum of guests' conviviality ratings.

 

Input
Employees are numbered from 1 to N. A first line of input contains a number N. 1 <= N <= 6 000. Each of the subsequent N lines contains the conviviality rating of the corresponding employee. Conviviality rating is an integer number in a range from -128 to 127. After that go T lines that describe a supervisor relation tree. Each line of the tree specification has the form:
L K
It means that the K-th employee is an immediate supervisor of the L-th employee. Input is ended with the line
0 0

 

Output
Output should contain the maximal sum of guests' ratings.

 

Sample Input
711111111 32 36 47 44 53 50 0

 

Sample Output
5

 

4、AC代码:

#include
#include
using namespace std;#define N 6005vector
vec[N];int rating[N];int f[N];int dp[N][2];//dp[i][1]表示i结点选择,dp[i][0]表示i结点不选择void dfs(int root){ dp[root][1]=rating[root]; for(int i=0; i

 

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

你可能感兴趣的文章
忽略图片透明区域的事件(Flex)
查看>>
忽略图片透明区域的事件(Flex)
查看>>
AS3 Flex基础知识100条
查看>>
Flex动态获取flash资源库文件
查看>>
flex中设置Label标签文字的自动换行
查看>>
Flex 中的元数据标签
查看>>
flex4 中创建自定义弹出窗口
查看>>
01Java基础语法-11. 数据类型之间的转换
查看>>
01Java基础语法-13. if分支语句的灵活使用
查看>>
01Java基础语法-15.for循环结构
查看>>
01Java基础语法-16. while循环结构
查看>>
01Java基础语法-17. do..while循环结构
查看>>
01Java基础语法-18. 各种循环语句的区别和应用场景
查看>>
01Java基础语法-19. 循环跳转控制语句
查看>>
Django框架全面讲解 -- Form
查看>>
socket,accept函数解析
查看>>
今日互联网关注(写在清明节后):每天都有值得关注的大变化
查看>>
”舍得“大法:把自己的优点当缺点倒出去
查看>>
[今日关注]鼓吹“互联网泡沫,到底为了什么”
查看>>
[互联网学习]如何提高网站的GooglePR值
查看>>