当前位置:网站首页>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 代码
边栏推荐
- 交换 生成树 知识总结
- 网络安全笔记5——数字签名
- [Concept of Theory of Knowledge] "Progress in the Theory of Reason" University of Leuven 2022 latest 220-page doctoral dissertation
- ZZULIOJ 1116 Delete elements [delete]
- 关于“码农”的一点自嘲解构
- 组合模式:Swift 实现
- mysql出现:ERROR 1524 (HY000): Plugin ‘123‘ is not loaded
- 短视频软件开发——平台同质化如何破局
- [C language] Floating point number rounding
- 第3章-线性方程组(3)
猜你喜欢
随机推荐
JWT 实现登录认证 + Token 自动续期方案
GPU加速Pinterest推荐模型,参数量增加100倍,用户活跃度提高16%
AUTOCAD——减少样条曲线控制点数、CAD进阶练习(三)
TCP/IP笔记
从产品角度看 L2 应用:为什么说这是一个游乐场?
Text selection rounded style border-radius
STM32封装ESP8266一键配置函数:实现实现AP模式和STA模式切换、服务器与客户端创建
PTA 7-2 Summation and Counting of Diagonal Elements of Square Matrices Solution
[Microservice Architecture] Microservices and SOA Architecture (2)
POJ 1026 Cipher (置换群)
MongoDB数据库笔记
what is rtems
越折腾越好用的 3 款开源 APP
leetcode:334. 递增的三元子序列
网络安全笔记6——数字证书与公钥基础设施
mysql5.7 installation and deployment - yum installation
chart.js horizontal column chart plugin
「时序数据库」使用cassandra进行时间序列数据扫描
企业如何判断数据治理是否成功?
[Azure Cloud] What is the difference between a service endpoint and a private link?point of view (1)









