HDU 5325 Crazy Bobo(思路+dfs 记忆化)
Crazy Bobo
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 612 Accepted Submission(s): 189
All the weights are distrinct.
A set with m nodes v1,v2,...,vm is
a Bobo Set if:
- The subgraph of his tree induced by this set is connected.
- After we sort these nodes in set by their weights in ascending order,we get u1,u2,...,um,(that
is,wui<wui+1 for
i from 1 to m-1).For any node x in
the path from ui to ui+1(excluding ui and ui+1),should
satisfy wx<wui.
Your task is to find the maximum size of Bobo Set in a given tree.
The first line contains a integer n (1≤n≤500000).
Then following a line contains n integers w1,w2,...,wn (1≤wi≤109,all
the wi is
distrinct).Each of the following n-1 lines contain 2 integers ai and bi,denoting
an edge between vertices ai and bi (1≤ai,bi≤n).
The sum of n is not bigger than 800000.
7
3 30 350 100 200 300 400
1 2
2 3
3 4
4 5
5 6
6 7
5
pid=5326" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5326
5324 5323 5322 5321/* 參考此人博客 :http://www.mamicode.com/info-detail-948802.html
记得用c++交 */ #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
using namespace std; #define N 800005 vector<int>g[N];
int n;
int ans[N];
int a[N]; int dfs(int u)
{
if(ans[u]) return ans[u];
ans[u]=1;
for(int i=0;i<g[u].size();i++)
{
int to=g[u][i];
ans[u]+=dfs(to);
}
return ans[u];
} int main()
{
int i,j;
while(~scanf("%d",&n))
{
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
g[i].clear();
memset(ans,0,sizeof(ans));
int u,v;
i=n-1;
while(i--)
{
scanf("%d%d",&u,&v);
if(a[u]<a[v]) g[u].push_back(v);
else g[v].push_back(u);
}
int temp=0;
for(i=1;i<=n;i++)
{
temp=max(temp,dfs(i));
}
printf("%d\n",temp);
}
return 0;
}
HDU 5325 Crazy Bobo(思路+dfs 记忆化)的更多相关文章
- hdu 5325 Crazy Bobo dfs
// hdu 5325 Crazy Bobo // // 题目大意: // // 给你一棵树,树上每一个节点都有一个权值w,选择尽可能多的节点, // 这些节点相互联通,而且依照权值升序排序之后得到节 ...
- hdu 5325 Crazy Bobo (树形dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Crazy Bobo Time Limit: 6000/3000 MS (Java ...
- 2015 Multi-University Training Contest 3 hdu 5325 Crazy Bobo
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total ...
- DFS/BFS+思维 HDOJ 5325 Crazy Bobo
题目传送门 /* 题意:给一个树,节点上有权值,问最多能找出多少个点满足在树上是连通的并且按照权值排序后相邻的点 在树上的路径权值都小于这两个点 DFS/BFS+思维:按照权值的大小,从小的到大的连有 ...
- 不要62 hdu 2089 dfs记忆化搜索
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意: 给你两个数作为一个闭区间的端点,求出该区间中不包含数字4和62的数的个数 思路: 数位dp中 ...
- poj1088-滑雪 【dfs 记忆化搜索】
http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 79806 ...
- dfs+记忆化搜索,求任意两点之间的最长路径
C.Coolest Ski Route 题意:n个点,m条边组成的有向图,求任意两点之间的最长路径 dfs记忆化搜索 #include<iostream> #include<stri ...
- hdu 1078(dfs记忆化搜索)
题意:容易理解... 思路:我开始是用dfs剪枝做的,968ms险过的,后来在网上学习了记忆化搜索=深搜形式+dp思想,时间复杂度大大降低,我个人理解,就是从某一个点出发,前面的点是由后面的点求出的, ...
- hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)
pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...
随机推荐
- JDBC性能优化
一.使用PreparedStatement的Batch功能 参见本人一下文章:http://blog.csdn.net/lmb55/article/details/50631062 二.选择合适的光标 ...
- Understanding and Analyzing Application Crash Reports
Introduction When an application crashes, a crash report is created and stored on the device. Crash ...
- 少啰嗦!一分钟带你读懂Java的NIO和经典IO的区别
1.引言 很多初涉网络编程的程序员,在研究Java NIO(即异步IO)和经典IO(也就是常说的阻塞式IO)的API时,很快就会发现一个问题:我什么时候应该使用经典IO,什么时候应该使用NIO? 在本 ...
- Linux系统安装,组成及开关机
Linux系统安装,组成及开关机 系统安装 swap分区用于实现虚拟内存,文件系统类型是swap. /分区用于存放包括系统程序和用户数据在内的所有数据,文件系统类型是ext4. 系统组成 Linux内 ...
- eBPF监控工具bcc系列五工具funccount
eBPF监控工具bcc系列五工具funccount funccount函数可以通过匹配来跟踪函数,tracepoints 或USDT探针.例如所有以vfs_ 开头的内核函数. ./funccount ...
- Python基础之简介
参考原文 廖雪峰Python教程 什么是Python? Python是一种计算机程序设计语言,又被称为胶水语言,它是高级的编程语言. Python能干什么? 网站后端程序员.自动化运维.数据分析师.游 ...
- Educational Codeforces Round 57 (Rated for Div. 2) 前三个题补题
感慨 最终就做出来一个题,第二题差一点公式想错了,又是一波掉分,不过我相信我一定能爬上去的 A Find Divisible(思维) 上来就T了,后来直接想到了题解的O(1)解法,直接输出左边界和左边 ...
- ubuntu 常见的操作命令
原博客地址为:https://blog.csdn.net/qq_33421080/article/details/76551554 1.cd命令: cd:切换到当前用户根目录,默认[/home/用户名 ...
- 52.基于doc value正排索引的聚合内部原理
主要知识点: 本节没有太懂,以后复习时补上 聚合分析的内部原理是什么????aggs,term,metric avg max,执行一个聚合操作的时候,内部原理是怎样的呢?用了什么样的数据结 ...
- Python介绍以及Python 优缺点
Python是先编译成字节码,然后在解释执行的一门语言,而不是单纯的解释型语言 Python应用场景: Web应用开发. 操作系统管理,服务器运维的自动化脚本, 网络爬虫 科学计算 桌面软件 游戏 服 ...