Anniversary party

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6078    Accepted Submission(s): 2752

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
7
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5
0 0
 
Sample Output
5
 
Source
Ural State University Internal Contest October'2000 Students Session
 

树形DP入门题目、、

加了一个输入输出外挂、、无耻地飘进首页、、

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cmath>
#include <map>
#include <vector>
#include <iterator>
#include <cstring>
#include <string>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define INF 0x7fffffff
#define ll long long
#define N 6010 struct Edge
{
int to,next;
}edge[N<<];
int head[N],tot;
int n;
int f[N];
int val[N];
int vis[N];
int dp[N][]; template <class T>
inline bool input(T &ret)
{
char c; int sgn;
if(c=getchar(),c==EOF) return ;
while(c!='-'&&(c<''||c>'')) c=getchar();
sgn=(c=='-')?-:;
ret=(c=='-')?:(c-'');
while(c=getchar(),c>=''&&c<='') ret=ret*+(c-'');
ret*=sgn;
return ;
} inline void out(int x)
{
if(x>) out(x/);
putchar(x%+'');
} void init()
{
tot=;
memset(head,-,sizeof(head));
memset(f,,sizeof(f));
memset(dp,,sizeof(dp));
memset(vis,,sizeof(vis));
} void add(int x,int y)
{
edge[tot].to=y;
edge[tot].next=head[x];
head[x]=tot++;
} void dfs(int u)
{
for(int i=head[u];i!=-;i=edge[i].next)
{
int v=edge[i].to;
if(!vis[v])
{
vis[v]=;
dfs(v);
dp[u][]+=dp[v][];
dp[u][]+=max(dp[v][],dp[v][]);
}
}
dp[u][]+=val[u];
} int main()
{
int i;
while(input(n))
{
init();
for(i=;i<=n;i++)
{
input(val[i]);
}
int a,b;
while()
{
input(a);
input(b);
if(a+b==) break;
f[a]=b;
add(b,a);
}
int root=;
while(f[root])
{
root=f[root];
}
vis[root]=;
dfs(root);
out(max(dp[root][],dp[root][]));
putchar('\n');
}
return ;
}

[HDU 1520] Anniversary party的更多相关文章

  1. 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 ...

  2. hdu 1520 Anniversary party(第一道树形dp)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1520 Anniversary party Time Limit: 2000/1000 MS (Java ...

  3. HDU 1520.Anniversary party 基础的树形dp

    Anniversary party Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. POJ 2342 &&HDU 1520 Anniversary party 树形DP 水题

    一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点) ...

  5. HDU 1520 Anniversary party [树形DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 题目大意:给出n个带权点,他们的关系可以构成一棵树,问从中选出若干个不相邻的点可能得到的最大值为 ...

  6. hdu 1520 Anniversary party 基础树dp

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  7. hdu 1520 Anniversary party || codevs 1380 树形dp

    Anniversary party Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. hdu 1520 Anniversary party(入门树形DP)

    Anniversary party Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6926   Accepted: 3985 ...

  9. 题解报告:hdu 1520 Anniversary party(树形dp入门)

    Problem Description There is going to be a party to celebrate the 80-th Anniversary of the Ural Stat ...

随机推荐

  1. springmvc学习(一)helloworld实例

    今天介绍的是springmvc的学习,越来越多的企业开始选择springmvc+mybatis来构建系统架构,在电商热门的今天,springmvc+mybatis已成为电商项目架构的很好搭配.Spri ...

  2. C++成员变量初始化顺序问题

    由于面试题中,考官出了一道简单的程序输出结果值的题:如下, class A { private: int n1; int n2; public: A():n2(0),n1(n2+2){} void P ...

  3. 模板:函数memset

    需要的头文件 <memory.h> or <string.h> memset   函数介绍 void *memset(void *s, int ch, size_t n); 函 ...

  4. Java Web开发之详解JSP

    JSP作为Java Web开发中比较重要的技术,一般当作视图(View)的技术所使用,即用来展现页面.Servlet由于其本身不适合作为表现层技术,所以一般被当作控制器(Controller)所使用, ...

  5. 关于.NET技术前途问题的讨论

    我去年曾经在论坛发起过关于.NET技术前途问题这个话题的讨论,也引起了很多同行和朋友的回复,时间过去大半年,自己也有了一些新的理解.本文的目的就是将其中一些精彩的观点整理出来并谈谈自己的观点. 引子 ...

  6. .Net 中资源的使用方式

    近期要在小丸工具箱中添加一个启动画面,画面中需要使用一个GIF动图.经过学习和实验,总结了几个读取资源的方式,罗列如下. 一.使用外部资源 Image img = Image.FromFile(&qu ...

  7. 使用webstorm上传代码到github

    使用webstorm上传代码到github 字数681 阅读330 评论0 喜欢5 之前使用过webstorm上传代码到github,过了几个月竟然发现自己忘记了,好记性不如烂笔头啊,今天又重新用了一 ...

  8. 设置nginx禁止通过IP访问服务器的方法

    在Nginx上设置禁止通过IP访问服务器,只允许通过域名访问,以避免别人把未备案的域名解析到自己的服务器IP而导致服务器被断网. nginx的默认虚拟主机允许用户通过IP访问,或者通过未设置的域名访问 ...

  9. 修改centos环境变量

    1.vim /etc/profile 2.PATH=$PATH:/usr/local/php/bin;export PATH 3.source /etc/profile

  10. 将ecshop中的session机制重写,从DB移植到Memcache中去

    <?php if (!defined('IN_ECS')) { die('Hacking attempt'); } /*------------------------------------- ...