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 ...
随机推荐
- Appium自动化学习1
1.Appium-desktop配置Desired Capabilities { "platformName": "Android", "platfo ...
- FPGA笔试必会知识点1--数字电路基本知识
组合逻辑与时序逻辑 组合逻辑电路:任意时刻电路输出的逻辑状态仅仅取决于当时输入的逻辑状态,而与电路过去的工作状态无关. 时序逻辑电路:任意时刻电路输出的逻辑状态不仅取决于当时输入的逻辑状态,而与电路过 ...
- python3 写excel文件 xlsxwriter模块
之前一直用这个传说中可以让python飞起来的xlwings模块来写入excel文件,今天发现xlsxwriter模块,发现这才是飞起来的feel!! 使用体验对比: xlwings:写入7000+单 ...
- python2操作MySQL
#coding=utf-8 import MySQLdb conn = MySQLdb.connect(host='localhost',user='root',passwd='123456' ...
- jtable时间编辑器
最近在做一个项目,很烦,用的swing,但是不管怎样也还是啃下来了,但是碰到一个问题,要在jtable里编辑时用一个时间选择器,因为走了许多弯路,找到挺多jar包,耗时较久,所以记录一下,便于以后查阅 ...
- react-native-table-component, react-native 表格
使用 react-native-table-component, 加上 FlatList 组件,实现可以下拉刷新,上拉加载的demo import React, { Component } from ...
- Redis广播
参见:http://blog.csdn.net/u011734144/article/details/51782085
- Oracle :多表更新多个字段
https://blog.csdn.net/funnyfu0101/article/details/52765235 总体原则:1)更新的时候一定要加where条件,否则必然引起该字段的所有记录更新 ...
- [Docker] 容器持久化数据的首选机制 Volume
Volume 是 docker 容器生成持久化数据的首选机制.bind mounts 依赖主机机器的目录机构,volume 完全由 docker 管理.volume 较 bind mounts 有几个 ...
- jquery中checkbox的选中,反选,全不选 注意1.6版本以上将attr改成prop
<script type="text/javascript"> $(function () { // 全选 $("#btnCheckAll").bi ...