当前位置:网站首页>HDU 1520 Anniversary party (tree dp)
HDU 1520 Anniversary party (tree dp)
2022-08-10 11:09:00 【51CTO】
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
Sample Output
题意
输入 n
nodes and their active values,然后输入 a b
,代表 b
是 a
的上司,Supervisors and subordinates who are directly related cannot participate at the same timePatty,求Patty的最大活跃值.
思路
You can first build a tree according to the given relationship.
Each node has two states,To participate or not to participate, 0
Representatives do not participate, 1
代表参加.
我们定义 dp[i][0]
为以 i
is a subtree of the root and i
The maximum active value you can get by not participating, dp[i][1]
为 i
Participate in the maximum active value you can get.
状态转移方程:
dp[i][0]+=max(dp[j][1],dp[j][0]);
dp[i][1]+=dp[j][0];
其中 j
是 i
的所有下属.
AC 代码
边栏推荐
- Several small projects that I have open sourced over the years
- 《MySQL高级篇》六、索引的创建与设计原则
- STM32封装ESP8266一键配置函数:实现实现AP模式和STA模式切换、服务器与客户端创建
- 1-IMU参数解析以及选择
- [Azure Cloud] What is the difference between a service endpoint and a private link?point of view (1)
- bus event bus use
- JWT implements login authentication + Token automatic renewal scheme
- js对象转FormData对象(一般用于上传)
- 「时序数据库」使用cassandra进行时间序列数据扫描
- 【Azure云】服务端点和私有链接有什么区别?观点(1)
猜你喜欢
mysql5.7 installation and deployment - yum installation
The impact of development mode on testing
Kyligence 通过 SOC 2 Type II 审计,以可信赖的企业级产品服务全球客户
使用cpolar远程连接群晖NAS(升级固定链接2)
chart.js horizontal column chart plugin
网络安全笔记6——数字证书与公钥基础设施
Redis (three) - detailed configuration file, publish and subscribe, new data types
String interception function in SQL
Introduction to cross-end development of Taro applet
js猜拳小游戏源码
随机推荐
Memory problems difficult to locate, it is because you do not use ASAN
Situation丨The intrusion of hackers intensifies, and the shooting range sets up a "defense shield" for network security
关于“码农”的一点自嘲解构
Summary of whitespace, space and escape characters in C language
ZZULIOJ 1124: Merge two sorted arrays
Text selection rounded style border-radius
[C language] Floating point number rounding
PTA 7-2 Summation and Counting of Diagonal Elements of Square Matrices Solution
《MySQL高级篇》六、索引的创建与设计原则
兼容移动和PC的loading加载和toast消息插件
8月份DB-Engines 数据库排行榜最新战况
"Scalability" extensibility best practices: lessons from eBay
Redis6 (1) - Introduction to NoSQL Database and Installation of Redis
用proteus直接仿真stm32-可以完全丢弃编程器
4 of huawei offer levels, incredibly side is easing the bit in the interview ali?
js猜拳小游戏源码
[C language] Header file #include
, conio is Console Input/Output (console input and output) 什么是抽象类
程序员追求技术夯实基础学习路线建议
Gold, nine, silver and ten job-hopping seasons: technical interview questions and answers on Alibaba, Baidu, JD.com, and Meituan