hdu 1520
Anniversary party
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6401 Accepted Submission(s): 2862
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.
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
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5
0 0
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define sfl(n) scanf("%lld", &n)
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%lld\n", n)
#define MAXN 6005
int w[MAXN];
bool f[MAXN] = {false};
vector<int> v[MAXN];
int d[MAXN][];
bool vis[MAXN] = {false};
void dp(int root)
{
if(vis[root]) return ;
vis[root] = true;
int siz = v[root].size();
repu(i, , siz) dp(v[root][i]); repu(i, , siz)
{
d[root][] += max(d[v[root][i]][], d[v[root][i]][]);
d[root][] += d[v[root][i]][];
}
return ;
}
int main()
{
int n;
while(~sfi(n))
{
_cle(vis, false);
_cle(f, false);
repu(i, , n + )
{
sfi(w[i]);
v[i].clear();
d[i][] = ;
d[i][] = w[i];
}
int x, y;
while(sfi(x), sfi(y), x + y)
{
v[y].push_back(x);
f[x] = true;
}
int root;
repu(i, , n + ) if(!f[i])
{
root = i;
break;
}
dp(root);
pfi(max(d[root][], d[root][]));
//repu(i, 1, n + 1) printf("%d %d\n", d[i][0], d[i][1]);
} return ;
}
hdu 1520的更多相关文章
- HDU 1520 树形dp裸题
1.HDU 1520 Anniversary party 2.总结:第一道树形dp,有点纠结 题意:公司聚会,员工与直接上司不能同时来,求最大权值和 #include<iostream> ...
- 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 树形DP入门
HDU 1520 [题目链接]HDU 1520 [题目类型]树形DP &题意: 某公司要举办一次晚会,但是为了使得晚会的气氛更加活跃,每个参加晚会的人都不希望在晚会中见到他的直接上司,现在已知 ...
- HDU 1520:Anniversary party(树形DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Problem Description There i ...
- 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 基础的树形dp
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1520(简单树形dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 思路:dp[u][0]表示不取u的最大价值,dp[u][1]表示取u的最大价值,于是有dp[u] ...
- hdu 1520 Anniversary party(第一道树形dp)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Time Limit: 2000/1000 MS (Java ...
- hdu 1520 树形DP基础
http://acm.hdu.edu.cn/showproblem.php?pid=1520 父节点和子节点不能同时选. http://blog.csdn.net/woshi250hua/articl ...
随机推荐
- 在服务器端如何提取checkbox提交的数据?
HttpServeletRequest 单个字符串,getParameters() 多个字符串,getParametersValues(),返回一个数组,需要提前定义一个数组
- servlet&jsp高级:第四部分
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- python 自动生成C++代码 (代码生成器)
python 代码自动生成的方法 (代码生成器) 遇到的问题 工作中遇到这么一个事,需要写很多C++的底层数据库类,但这些类大同小异,无非是增删改查,如果人工来写代码,既费力又容易出错:而借用pyth ...
- DICOM标准相关资料
由于需要阅读影像,对DICOM需要先熟悉起来.关于DICOM,找了一些资料,可以学习.如下: DICOM标准:http://dicom.nema.org/standard.html 中文 DICOM ...
- HDU 5430 Reflect(欧拉函数)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5430 从镜面材质的圆上一点发出一道光线反射NNN次后首次回到起点. 问本质不同的发射的方案数. 输入描述 ...
- Android实现简单短信发送器
布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:to ...
- [转载] 理解RESTful架构
原文: http://www.ruanyifeng.com/blog/2011/09/restful.html 理解RESTful架构 作者: 阮一峰 日期: 2011年9月12日 越来越多的人开 ...
- [转载] 深入 nginx 架构
原文: http://www.cnbeta.com/articles/402709.htm 了解 nginx 架构帮助我们学习如何开发高性能 web 服务. 为了更好地理解设计,你需要了解NGINX是 ...
- js获取select字段值的方法
var index = obj.selectedIndex; // 选中索引 var value = obj.options[index].value; // 选中值 var schoolName = ...
- 免费在线客服QQ_网页接入及使用说明
首先,注册一个QQ (haha,我觉得也是废话) 到QQ推广的网站设置,生成代码 链接:http://shang.qq.com/v3/widget.html 选择“免费开通”,然后就会看到下图,一般只 ...