Crazy Bobo

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)

Total Submission(s): 612    Accepted Submission(s): 189

Problem Description
Bobo has a tree,whose vertices are conveniently labeled by 1,2,...,n.Each node has a weight wi.
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.
 
Input
The input consists of several tests. For each tests:

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.
 
Output
For each test output one line contains a integer,denoting the maximum size of Bobo Set.
 
Sample Input
7
3 30 350 100 200 300 400
1 2
2 3
3 4
4 5
5 6
6 7
 
Sample Output
5
 
Source
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  

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 记忆化)的更多相关文章

  1. hdu 5325 Crazy Bobo dfs

    // hdu 5325 Crazy Bobo // // 题目大意: // // 给你一棵树,树上每一个节点都有一个权值w,选择尽可能多的节点, // 这些节点相互联通,而且依照权值升序排序之后得到节 ...

  2. hdu 5325 Crazy Bobo (树形dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Crazy Bobo Time Limit: 6000/3000 MS (Java ...

  3. 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 ...

  4. DFS/BFS+思维 HDOJ 5325 Crazy Bobo

    题目传送门 /* 题意:给一个树,节点上有权值,问最多能找出多少个点满足在树上是连通的并且按照权值排序后相邻的点 在树上的路径权值都小于这两个点 DFS/BFS+思维:按照权值的大小,从小的到大的连有 ...

  5. 不要62 hdu 2089 dfs记忆化搜索

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意: 给你两个数作为一个闭区间的端点,求出该区间中不包含数字4和62的数的个数 思路: 数位dp中 ...

  6. poj1088-滑雪 【dfs 记忆化搜索】

    http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 79806 ...

  7. dfs+记忆化搜索,求任意两点之间的最长路径

    C.Coolest Ski Route 题意:n个点,m条边组成的有向图,求任意两点之间的最长路径 dfs记忆化搜索 #include<iostream> #include<stri ...

  8. hdu 1078(dfs记忆化搜索)

    题意:容易理解... 思路:我开始是用dfs剪枝做的,968ms险过的,后来在网上学习了记忆化搜索=深搜形式+dp思想,时间复杂度大大降低,我个人理解,就是从某一个点出发,前面的点是由后面的点求出的, ...

  9. hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)

    pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/ ...

随机推荐

  1. Java:一个简捷的可分页的ResultSet实现

    内容 前言 JDBC和分页 和具体数据库相关的实现方法 另一种繁琐的实现方法 使用Vector进行分页 一个新的Pageable接口及其实现 Pageable的使用方法 总结 参考资料 关于作者 前言 ...

  2. 通俗理解LDA主题模型(boss)

    0 前言 看完前面几篇简单的文章后,思路还是不清晰了,但是稍微理解了LDA,下面@Hcy开始详细进入boss篇.其中文章可以分为下述5个步骤: 一个函数:gamma函数 四个分布:二项分布.多项分布. ...

  3. 北大ACM(POJ1018-Communication System)

    Question:http://poj.org/problem?id=1018 问题点:枚举. Memory: 564K Time: 329MS Language: C++ Result: Accep ...

  4. LR中日志参数的设置

    LR中日志参数的设置 1.Run-Time Setting日志参数的设置 在loadrunner的vuser菜单下的Run-Time Setting的General的LOG选项中可以对在执行脚本时Lo ...

  5. js获取微信版本号的方法

    微信现在几乎已经普遍在使用,但是微信版本一直在更新,不同的版本有不同的功能,于是了解微信的版本号很重要,以便自己及时更新体验新的功能.那么如何用js获取微信版本号呢? 一.判断微信版本号 ? 1 2 ...

  6. Unity中播放带有alpha通道格式为Mp4的视频

    问题: Unity中实现播放透明的MP4视频时出现黑点 解决办法:    使用Unity自带的shader去除黑点 1:shader代码如下所示 Shader "Unlit/NewUnlit ...

  7. MySQL各种版本的下载方式

    1.在百度上搜“MySQL”,进入官网 原文地址:https://blog.csdn.net/mieleizhi0522/article/details/79109195

  8. FTP配置

    常用的匿名FTP配置项   anonymous_enable=YES           是否允许匿名用户访问   anon_umask=022                匿名用户所上传文件的权限 ...

  9. oop设计模式抽象总结

    创建型模式: 一.简单工厂,工厂方法,抽象工厂 简单工厂:只有一层抽象,由工厂去获得抽象类的具体对象,工厂内的方法可以看做静态方法 工厂方法:有两个抽象,工厂的抽象和具体类的抽象. 举个例子: 有个汽 ...

  10. Django DTL模板语法中的判断

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...