当前位置:网站首页>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 代码
边栏推荐
- mysql5.7 installation and deployment - yum installation
- [Microservice Architecture] Microservices and SOA Architecture (2)
- ZZULIOJ 1124: Merge two sorted arrays
- 【Azure云】服务端点和私有链接有什么区别?观点(1)
- Gartner reiterates the important value of 'data weaving'
- 4 of huawei offer levels, incredibly side is easing the bit in the interview ali?
- "Time Series Database" uses cassandra to scan time series data
- Taro小程序跨端开发入门实战
- 第二十二章 源代码文件 REST API 参考(四)
- 组合模式:Swift 实现
猜你喜欢

从产品维度来看 我们为什么不能完全信任Layer2?

跨公网环境,路由策略,进行设备的访问

14 high-frequency handwritten JS interview questions and answers to consolidate your JS foundation

【勇敢饭饭,不怕刷题之链表】链表倒数节点问题

Pycharm终端出现PS问题、conda或activate不是内部命令问题..

蔚来-软件开发工程师一面记录

3 injured in 'electrical accident' at Google data center

Redis6 (1) - Introduction to NoSQL Database and Installation of Redis
![[C language] Floating point number rounding](/img/ff/3f256deaa5ec82d692828c67cfb0fa.png)
[C language] Floating point number rounding

开发模式对测试的影响
随机推荐
OneFlow source code parsing: operator instructions executed in a virtual machine
4 of huawei offer levels, incredibly side is easing the bit in the interview ali?
Redis(三)——配置文件详解、发布和订阅、新数据类型
"Chief Engineer" Principal (Principal) engineer's way of training
GPU加速Pinterest推荐模型,参数量增加100倍,用户活跃度提高16%
第3章-线性方程组(3)
[C language] Floating point number rounding
Dalian University of Technology & Pengcheng & UAE propose a mixed-scale triple network ZoomNet for camouflaged target detection, with SOTA performance!
1-IMU参数解析以及选择
2022.8.9-----leetcode.1413
Introduction to cross-end development of Taro applet
HCIP ---- VLAN
2022.8.7-----leetcode.636
EasyCVR级联时,修改下级平台名称将不同步至上级平台
跨公网环境,路由策略,进行设备的访问
OSSCore 开源解决方案介绍
使用cpolar远程连接群晖NAS(升级固定链接2)
14 high-frequency handwritten JS interview questions and answers to consolidate your JS foundation
owl.carousel海报卡片Slider轮播切换
Taro小程序跨端开发入门实战