HDU 1520 Anniversary party(DFS或树形DP)
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.
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
7
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5
0 0
5
#include<cstdio> #define N 6005 struct p
{
int fm;
int child;
int brother;
int att;
int no;
void init()
{
no=0;
fm=0;
brother=0;
child=0;
}
int Max()
{
return att>no? att:no;
}
}num[N]; void dfs(int x)
{
int child=num[x].child;
while(child)
{
dfs(child);
num[x].att+=num[child].no;
num[x].no+=num[child].Max();
child=num[child].brother;
}
} int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
num[i].init();
scanf("%d",&num[i].att);
}
int a,b;
while(scanf("%d %d",&a,&b),a||b)
{
num[a].fm=b;
num[a].brother=num[b].child;
num[b].child=a;
}
for(int i=1;i<=n;i++)
{
if(num[i].fm==0)
{
dfs(i);
printf("%d\n",num[i].Max());
break;
}
}
}
return 0;
}
HDU 1520 Anniversary party(DFS或树形DP)的更多相关文章
- HDU 1520.Anniversary party 基础的树形dp
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- TTTTTTTTTTT hdu 1520 Anniversary party 生日party 树形dp第一题
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1520 Anniversary party || codevs 1380 树形dp
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划)
POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划) Descri ...
- hdu 1520 Anniversary party(第一道树形dp)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Time Limit: 2000/1000 MS (Java ...
- POJ 2342 &&HDU 1520 Anniversary party 树形DP 水题
一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点) ...
- HDU 1520 Anniversary party [树形DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 题目大意:给出n个带权点,他们的关系可以构成一棵树,问从中选出若干个不相邻的点可能得到的最大值为 ...
- [HDU 1520] Anniversary party
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu_5293_Tree chain problem(DFS序+树形DP+LCA)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5293 被这题打蹦了,看着题解写的,很是爆炸,确实想不到,我用的DFS序+LCA+树形DP,当然也可以写 ...
随机推荐
- 【BZOJ2006】【NOI2010】超级钢琴
题意: Description 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号为1至n.第i个音符 ...
- HDU-5693 D Game 动态规划 两次动规
题目链接:https://cn.vjudge.net/problem/HDU-5693 题意 中文题 这个游戏是这样的,首先度度熊拥有一个公差集合{D},然后它依次写下N个数字排成一行.游戏规则很简单 ...
- BZOJ 4033[HAOI2015] 树上染色(树形DP)
4033: [HAOI2015]树上染色 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 3188 Solved: 1366[Submit][Stat ...
- [codevs3657]括号序列
题目大意:有一列只有'(',')','[',']'构成的括号序列,求在序列中至少加上多少括号,能使该序列合法. 解题思路:区间dp. 我们以$f[i][j]$表示把区间$[i,j]$添成合法括号所需的 ...
- qume-kvm 命令管理
sudo /etc/init.d/acpid start 安装管理包工具 sudo apt install libguestfs-tools [ qemu-kvm qemu-kvm-tools vir ...
- STM32为什么必须先配置时钟
首先,任何外设都需要时钟,51单片机,stm32,430等等,因为寄存器是由D触发器组成的,往触发器里面写东西,前提条件是有时钟输入. 51单片机不需要配置时钟,是因为一个时钟开了之后所有的功能都可以 ...
- C#-反射知识点(转载)
反射的用途: (1)使用Assembly定义和加载程序集,加载在程序集清单中列出模块,以及从此程序集中查找类型并创建该类型的实例. (2)使用Module了解包含模块的程序集以及模块中的 ...
- 微信公众号开发将war包导入新浪sae出现错误
JAVA_Error: Error for /wechat.do java.lang.NoSuchFieldError: INSTANCE at org.apache.http.impl.io.Def ...
- 8、java高级面向对象-重载、构造器重载、初始化块、this、super、对象构造和初始化分析、覆盖、toString
1.方法的重载(overload) 同一个类中同时存在一个以上的同名函数,参数个数或类型不同或顺序不同,称为方法的重载. 和返回值无关! 构造器重载:非默认构造器和默认构造器其实就是方法的重载. 2. ...
- hdu_2795,线段树,单点更新
#include<iostream> #include<cstdio> #include<cstring> #define lson l,m,rt<<1 ...