hdu 1520Anniversary party(简单树形dp)
Anniversary party
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4310 Accepted Submission(s): 1976
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<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
const int maxn=6005; vector<int> mq[maxn];
int dp[maxn][2]; void dfs(int cur,int p)
{
int i,nex;
for(i=0;i<mq[cur].size();i++)
{
nex=mq[cur][i];
if(nex==p) continue; dfs(nex,cur); //先找从cur这个点能够扩展的dp
dp[cur][0]+=max(dp[nex][0],dp[nex][1]);
dp[cur][1]+=dp[nex][0];
}
} int main()
{
int n,i;
int a,b; while(~scanf("%d",&n))
{
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++)
{
mq[i].clear();
scanf("%d",&dp[i][1]);
} while(scanf("%d%d",&a,&b)&&(a+b))
{
mq[a].push_back(b);
mq[b].push_back(a);
} dfs(1,0); int ans=max(dp[1][0],dp[1][1]);
printf("%d\n",ans);
} return 0;
}
hdu 1520Anniversary party(简单树形dp)的更多相关文章
- HDU 1520-Anniversary party(树形dp入门)
题意: n个人参加party,已知每人的欢乐值,给出n个人的工作关系树,一个人和他的顶头上司不能同时参加,party达到的最大欢乐值. 分析:dp[i][f],以i为根的子树,f=0,i不参加,f=1 ...
- HDU 4714 Tree2cycle (树形DP)
Tree2cycle Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Tot ...
- HDU 3899 简单树形DP
题意:一棵树,给出每个点的权值和每条边的长度, 点j到点i的代价为点j的权值乘以连接i和j的边的长度.求点x使得所有点到点x的代价最小,输出 虽然还是不太懂树形DP是什么意思,先把代码贴出来把. 这道 ...
- HDU 4705 Y (2013多校10,1010题,简单树形DP)
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...
- hdu 1054 Strategic Game (简单树形DP)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- POJ 2342 &&HDU 1520 Anniversary party 树形DP 水题
一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点) ...
- HDU 1520 Anniversary party [树形DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 题目大意:给出n个带权点,他们的关系可以构成一棵树,问从中选出若干个不相邻的点可能得到的最大值为 ...
- poj 2342 Anniversary party 简单树形dp
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3862 Accepted: 2171 ...
- HDU 1054 Strategic Game (树形dp)
题目链接 题意: 给一颗树,用最少的点覆盖整棵树. 每一个结点可以防守相邻的一个边,求最少的点防守所有的边. 分析: 1:以当前节点为根节点,在该节点排士兵守护道路的最小消耗.在这种情况下,他的子节点 ...
随机推荐
- window.opener方法的使用 js跨域
原文:window.opener方法的使用 js跨域 最近公司网站登陆加入了第三方登陆.可以用QQ直接登陆到我们网站,在login页面A中点QQ登陆时,调用了一个window.open文件打开一个lo ...
- 将文件放到Android模拟器的SD卡中的两种解决方法
两种方式:一.窗口界面操作1.打开DDMS页面2.打开File Explorer页,如果没有,在Window --> Show View -->File Explorer3.一般就在mnt ...
- Java ClassLoader深入讲解(转)
当JVM(Java虚拟机)启动时,会形成由三个类加载器组成的初始类加载器层次结构: bootstrap classloader | extension cla ...
- html类,id规范命名
DIV+CSS的命名规则 SEO(搜索引擎优化)有很多工作要做,其中对代码的优化是一个很关键的步骤.为了更加符合SEO的规范,下面中部IT网将对目前流行的CSS+DIV的命名规则整理如下: 页头:he ...
- Ubuntu 查找命令
Ubuntu 查找文件夹 使用find命令查找find / -name 文件夹名称 -type d找到结果中含有路径 查找命令 从根目录开始查找所有扩展名为.log的文本文件,并找出包含”ERROR” ...
- 无限递归的构造器和javap使用指南
无限递归的构造器和javap使用指南 public class ConstructorRecursion { ConstructorRecursion rc; { rc = newConstructo ...
- Java琐碎知识点
jps命令是JDK1.5提供的一条显示当前用户的所有java进程pid的指令,类似Linux上的ps命令简化版,Windows和linux/unix平台都可以用比较常用的参数:-q:只显示pid,不显 ...
- linux下可以和qq截屏比拟的工具hotshots
可以区域截图,并且对其进行编辑. 安装过程如下: sudo add-apt-repository ppa:ubuntuhandbook1/apps sudo apt-get update sudo a ...
- android代码集锦
调用root权限的应用: /** * 执行Command命令的函数 * * @param command 命令 * @return 执行结果 */ public static boolean runR ...
- Lazy evaluation
是一段源码,关于Lazy evaluation的,看了很久才懂,记录一下 一,lazy方法返回的比较复杂,一层一层将其剥开. wraps(func)跳转到curry(update_wrapper, f ...