HDU 1520.Anniversary party 基础的树形dp
Anniversary party
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12770 Accepted Submission(s): 5142
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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<bitset>
using namespace std;
#define PI acos(-1.0)
#define eps 1e-8
typedef long long ll;
typedef pair<int,int> P;
const int N=1e5+,M=1e5+;
const int inf=0x3f3f3f3f;
const ll INF=1e18+,mod=1e9+;
struct edge
{
int from,to;
int next;
};
edge es[M];
int cnt,head[N];
int in[N];
int dp[N][];
void init()
{
cnt=;
memset(head,-,sizeof(head));
memset(in,,sizeof(in));
memset(dp,,sizeof(dp));
}
void addedge(int u,int v)
{
cnt++;
es[cnt].from=u,es[cnt].to=v;
es[cnt].next=head[u];
head[u]=cnt;
}
void dfs(int u)
{
for(int i=head[u]; i!=-; i=es[i].next)
{
int v=es[i].to;
dfs(v);
dp[u][]+=dp[v][];
dp[u][]+=max(dp[v][],dp[v][]);
}
///cout<<u<<" * "<<dp[u][0]<<" * "<<dp[u][1]<<endl;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
init();
for(int i=; i<=n; i++) scanf("%d",&dp[i][]);
int u,v;
while(scanf("%d%d",&u,&v)&&!(u==&&v==))
{
addedge(v,u);
in[u]++;
}
int root;
for(int i=; i<=n; i++)
if(!in[i]) root=i;
dfs(root);
printf("%d\n",max(dp[root][],dp[root][]));
}
return ;
}
基础树形dp
HDU 1520.Anniversary party 基础的树形dp的更多相关文章
- 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 ...
- hdu 1520 Anniversary party 基础树dp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 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(DFS或树形DP)
Problem Description There is going to be a party to celebrate the 80-th Anniversary of the Ural Stat ...
- hdu 1561 The more, The Better(树形dp,基础)
The more, The Better Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- C#拷贝一个库的表到另外一个库中(的四种方式)
1.该方法 基本不能用于实际开发中 ,仅供学习参考 public string Copy() { //要复制的表名 string table = "AAAAA"; //构造连接字符 ...
- py库:threading
https://www.youtube.com/watch?v=DnTn3Yx-Nvg join功能: import threading import time def thread_job2(): ...
- c#中委托和事件(转)
C# 中的委托和事件 引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真 ...
- pymysql操作
import pymysql conn_mysql = pymysql.connect(host='127.0.0.1',port=3306,user='root',password='123456' ...
- Python conda安装 并安装Tensorflow
Python conda安装 1: 官网下载3版本 Anaconda2-2018.12-Windows-x86_64.exe, 安装完后配置环境变量 用户变量->PATH 编辑新增路径 C:\P ...
- 接口--Comparable接口【哈夫曼树】
我们在字符串中见到过CompareTo方法,知道这个方法是用于比较字符串顺序的,根据字典顺序进行排序.Java中很多类也都有CompareTo方法,甚至于排序算法的底层组成也是依赖于比较的,而这个比较 ...
- png 变透明
using System.Drawing Image image; image = Image.FromFile("d:\\1.png"); Bitmap bitma ...
- python学习Day9 内存管理
复习 :文件处理 1. 操作文件的三步骤:-- 打开文件:此时该文件在硬盘的空间被操作系统持有 | 文件对象被应用程序持用 -- 操作文件:读写操作 -- 释放文件:释放操作系统对文件在硬盘间的持有 ...
- Pearson 相关系数--最佳理解及相关应用
https://blog.csdn.net/wenbingoon/article/details/17414063
- day49 定位布局和过渡动画
复习 1.盒子在父级水平居中 margin: 0 auto; 2.文本样式操作 color: red; text-align: center; font: 900 30px/200px "S ...