poj2342 Anniversary party
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8028 | Accepted: 4594 |
Description
Input
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
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
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <stack>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#define FOR(i,x,n) for(long i=x;i<n;i++)
#define ll long long int
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAX_N 60
#define MAX_M 1005 using namespace std; struct node{
int number;
int rating;
int sonNum;
int son[];
int father;
};
node tree[];
//int visable[6005];
int dp[][];//0表示不去,1表示去 void dfs(int root){
FOR(i,,tree[root].sonNum){
dfs(tree[root].son[i]);
dp[root][]+=max(dp[tree[root].son[i]][],dp[tree[root].son[i]][]);
dp[root][]+=dp[tree[root].son[i]][];
}
} int main()
{
//freopen("input1.txt", "r", stdin);
//freopen("data.out", "w", stdout);
int n;
//memset(visable,0,sizeof(visable));
memset(dp,,sizeof(dp));
scanf("%d",&n);
FOR(i,,n+){
tree[i].father=i;
tree[i].sonNum=;
}
FOR(i,,n+){
scanf("%d",&dp[i][]);
}
int t1,t2;
FOR(i,,n){
scanf("%d %d",&t1,&t2);
if(!(t1+t2)){
break;
}
tree[t1].father=t2;
tree[t2].son[tree[t2].sonNum++]=t1;
}
int t=;
while(tree[t].father!=t){
t=tree[t].father;
}
dfs(t);
printf("%d",max(dp[t][],dp[t][]));
//fclose(stdin);
//fclose(stdout);
return ;
}
poj2342 Anniversary party的更多相关文章
- poj2342 Anniversary party (树形dp)
poj2342 Anniversary party (树形dp) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9128 ...
- [poj2342]Anniversary party_树形dp
Anniversary party poj-2342 题目大意:没有上司的舞会原题. 注释:n<=6000,-127<=val<=128. 想法:其实就是最大点独立集.我们介绍树形d ...
- DP Intro - Tree POJ2342 Anniversary party
POJ 2342 Anniversary party (树形dp 入门题) Anniversary party Time Limit: 1000MS Memory Limit: 65536K To ...
- POJ2342 Anniversary party(动态规划)(树形DP)
Anniversary party Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6635 Accepted: 3827 ...
- 树形dp poj2342 Anniversary party * 求最大价值
Description There is going to be a party to celebrate the 80-th Anniversary of the Ural State Univer ...
- poj2342 Anniversary party【树形dp】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4316097.html ---by 墨染之樱花 [题目链接]http://poj.org/p ...
- [poj2342]Anniversary party树形dp入门
题意:选出不含直接上下司关系的最大价值. 解题关键:树形dp入门题,注意怎么找出根节点,运用了并查集的思想. 转移方程:dp[i][1]+=dp[j][0];/i是j的子树 dp[i][0]+=max ...
- 【poj2342】 Anniversary party
http://poj.org/problem?id=2342 (题目链接) 题意 没有上司的舞会... Solution 树形dp入门题. dp[i][1]表示第i个节点的子树当节点i去时的最大值,d ...
- Anniversary party(hdu1520)(poj2342)题解
原题地址:http://poj.org/problem?id=2342 题目大意: 上司和下属不能同时参加派对,求参加派对的最大活跃值. 关系满足一棵树,每个人都有自己的活跃值(-128~127) 求 ...
随机推荐
- java解决手机上传竖拍照片旋转90\180\270度问题
<dependency> <groupId>com.drewnoakes</groupId> <artifactId>metadata-extracto ...
- Android自定义控件实战——滚动选择器PickerView
转载请声明出处http://blog.csdn.net/zhongkejingwang/article/details/38513301 手机里设置闹钟需要选择时间,那个选择时间的控件就是滚动选择器, ...
- Linux中查看文件夹占用磁盘大小
一.命令 ./ du -h ./ 查看当前目录占用空间 二.样例
- IEEE754标准的浮点数存储格式
操作系统 : CentOS7.3.1611_x64 gcc版本 :4.8.5 基本存储格式(从高到低) : Sign + Exponent + Fraction Sign : 符号位 Exponent ...
- 阿里云提示WordPress“/wp-includes/http.php输入IP验证不当”的解决办法
本文转自:https://www.liuzhishi.com/2931.html 标题: wordpress IP验证不当漏洞 简介: wordpress /wp-includes/http.php文 ...
- easyUI 异步加载树
$(function () { var selected = $('#depttree').tree('getSelected'); $('#depttree').tree({ checkbox: f ...
- zabbix之微信告警(python版):微信个人报警,微信企业号告警脚本
微信个人告警脚本 微信个人告警:使用个人微信,发送到微信群组,微信好友 两个脚本执行: 1)能连接网络2)先执行server.py,扫描登录微信,登录之后没有报错,打开新终端查看端口是否起来了3)在z ...
- Delphi如何处理在进行大量循环时,导致的应用程序没有响应的情况
一般用在比较费时的循环中,往往导致应用程序没有响应,此时在比较费时的程序体中加入Application.ProcessMessages即可解决,该语句的作用是检查并先处理消息队列中的其他消息. 例如, ...
- linux安全配置检查脚本_v0.8
脚本环境:RHEL6.* 脚本说明:该脚本作用为纯执行检测不涉及更改配置等操作,与直接上来就改安全配置等基线脚本相比相对安全一些.虽然如此,在你执行该脚本之前仍然建议你备份或快照一下目标系统. 代码部 ...
- 【iCore4 双核心板_ARM】例程二十八:FSMC实验——读写FPGA
实验现象: 1.先烧写FPGA程序,再烧写ARM程序,ARM程序烧写完毕后即开始读写RAM测试,测试成功,绿色ARM·LED亮,测试失败,红色ARM·LED闪烁. 2.测试成功,ARM通过映射寄存器来 ...