Codeforces 490F Treeland Tour(dp)
来源:互联网 发布:js验证手机号码格式 编辑:程序博客网 时间:2024/06/17 12:47
题目链接:Codeforces 490F Treeland Tour
类似于nlogn的递增上升子序列算法。
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 6005;const int inf = 0x3f3f3f3f;int N, R[maxn], D[maxn], ans = 0;vector<int> g[maxn];void init () {scanf("%d", &N);for (int i = 1; i <= N; i++)scanf("%d", &R[i]);for (int i = 0; i < N; i++)D[i] = inf;int a, b;for (int i = 1; i < N; i++) {scanf("%d%d", &a, &b);g[a].push_back(b);g[b].push_back(a);}}void dfs(int u, int f) {int idx = lower_bound(D, D + N, R[u]) - D;ans = max(ans, idx + 1);int tmp = D[idx];D[idx] = R[u];for (int i = 0; i < g[u].size(); i++) {if (g[u][i] == f) continue;dfs(g[u][i], u);}D[idx] = tmp;}int main () {init();for (int i = 1; i <= N; i++)dfs(i, 0);printf("%d\n", ans);return 0;}
阅读全文
0 0
- codeforces 490F Treeland Tour(dp)
- Codeforces 490F Treeland Tour(dp)
- Codeforces 490F Treeland Tour(dp)
- CodeForces 490F Treeland Tour
- Codeforces 490F. Treeland Tour 暴力+LIS
- [树上LIS 线段树合并] Codeforces 490F #279 (Div. 2) F. Treeland Tour
- Codeforces 490F Treeland Tour 树上的最长上升子序列
- Codeforces Round #279 (Div. 2) F. Treeland Tour
- Codeforces Round #279 (Div. 2) F. Treeland Tour(lis+dfs)
- codeforces 858F Wizard's Tour
- 【Codeforces 500F】Dp
- CodeForces 219D Choosing Capital for Treeland (树形dp)
- CodeForces 219D Choosing Capital for Treeland | 树形dp
- Codeforces 219D - Choosing Capital for Treeland(树形dp)
- codeforces 219D Choosing Capital for Treeland(树形DP)
- CodeForces 219D Choosing Capital for Treeland (树形DP)
- codeforces 219D D. Choosing Capital for Treeland(树形dp)
- CodeForces 219D-H - Choosing Capital for Treeland-树DP
- java基础---内部类的使用
- Java中如何把两个数组合并为一个
- 模拟进程队列管理——按照优先级入列
- css 选择器
- 微信小程序4 组件补完
- Codeforces 490F Treeland Tour(dp)
- 文章标题
- 页面foreach遍历显示数据时,当要操作某个具体项目时,项目id只能从遍历项目体里传递出来。---循环体里的,动态的页面条目,比较抽象【很容易忘!牢记思路】
- scrapy中的数据流向
- Linux 共享库:LD_LIBRARY_PATH 与ld.so.conf
- php中简单实现excel下载功能
- ADB 常用命令
- C++中的容器及相关操作
- 结构体指针