当前位置:网站首页>HDU 1520 Anniversary party (树型dp)
HDU 1520 Anniversary party (树型dp)
2022-08-10 10:33: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 个节点以及这些节点的活跃值,然后输入 a b ,代表 b 是 a 的上司,有直接关系的上司和下属不能同时参加Patty,求Patty的最大活跃值。
思路
可以先按照给出的关系建树。
每一个节点有两种状态,参加与不参加, 0 代表不参加, 1 代表参加。
我们定义 dp[i][0] 为以 i 为根的子树且 i 不参加所能得到的最大活跃值, dp[i][1] 为 i 参加所能得到的最大活跃值。
状态转移方程:
dp[i][0]+=max(dp[j][1],dp[j][0]);
dp[i][1]+=dp[j][0];
其中 j 是 i 的所有下属。
AC 代码
边栏推荐
- EasyCVR级联时,修改下级平台名称将不同步至上级平台
- 3 injured in 'electrical accident' at Google data center
- 突破次元壁垒,让身边的玩偶手办在屏幕上动起来!
- STM32封装ESP8266一键配置函数:实现实现AP模式和STA模式切换、服务器与客户端创建
- Techches Transformer the join wisdom source the author cao, visual basic model study
- chart.js水平柱状图插件
- 2022.8.7-----leetcode.636
- SQL与NoSQL最终会走向融合吗?
- leetcode:334. 递增的三元子序列
- OneFlow source code parsing: operator instructions executed in a virtual machine
猜你喜欢

Network Security Note 6 - Digital Certificates and Public Key Infrastructure

What is an abstract class

Research on motion capture system for indoor combined positioning technology

3D rotating text animation js special effects

String interception function in SQL

js guessing game source code

Redis (six) - transaction and lock mechanism of Redis6 (unfinished, to be supplemented)

chart.js水平柱状图插件

js猜拳小游戏源码

让软件飞——“X+”技术揭秘
随机推荐
Interviewer: Dao, in Service, the Controller, Util, divided into the Model?
Mobile and PC compatible loading and toast message plugins
2022.8.9-----leetcode.1413
Automated Testing and Selenium
ESP8266 教程1 — ESP8266硬件平台介绍
SQL中的字符串截取函数
三相380V整流后的电压
chart.js水平柱状图插件
runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
C语言空白符、空格符 与转义字符题点总结
JWT implements login authentication + Token automatic renewal scheme
首次入选OSDI顶会!腾讯提出超大规模推荐系统的模型低延时更新方案
TCP/IP笔记
用.bat文件做Airtest脚本的多设备批量运行
Three-phase 380V rectified voltage
Several small projects that I have open sourced over the years
String interception function in SQL
「首席工程师」首席(Principal )工程师修炼之道
database constraints
bus event bus use