【DP】 HDOJ 5406 CRB and Apple
来源:互联网 发布:qq飞车鸿黎耀世数据 编辑:程序博客网 时间:2024/06/05 04:47
用树状数组优化DP。。。。
#include <bits/stdc++.h>using namespace std;typedef long long LL;#define lowbit(x) (x&(-x))const int maxn = 1005;int tree[maxn][maxn];pair<int, int> a[maxn];int t[maxn], y[maxn], n, cnt;int cmp(pair<int, int> aa, pair<int, int> bb){if(aa.first != bb.first) return aa.first > bb.first;return aa.second < bb.second;}void add(int x, int y, int v){for(; y <= cnt; y += lowbit(y)) tree[x][y] = max(tree[x][y], v);}int query(int x, int y){int res = 0;for(; y; y -= lowbit(y)) res = max(res, tree[x][y]);return res;}void work(){cnt = 0;scanf("%d", &n);for(int i = 1; i <= n; i++) {scanf("%d%d", &a[i].first, &a[i].second);y[cnt++] = a[i].second;}sort(y, y+cnt);cnt = unique(y, y+cnt) - y;for(int i = 1; i <= n; i++) a[i].second = lower_bound(y, y+cnt, a[i].second) - y + 1;memset(tree, 0, sizeof tree);sort(a+1, a+n+1, cmp);for(int i = 1; i <= n; i++) {for(int j = 1; j <= cnt; j++) t[j] = query(j, a[i].second) + 1;for(int j = 1; j <= cnt; j++) {add(j, a[i].second, t[j]);add(a[i].second, j, t[j]);}}int ans = 0;for(int i = 1; i <= cnt; i++) ans = max(ans, query(i, cnt));printf("%d\n", ans);}int main(){int _;scanf("%d", &_);while(_--) work();return 0;}
0 0
- 【DP】 HDOJ 5406 CRB and Apple
- HDOJ 5406 CRB and Apple 树状数组优化DP
- hdu 5406 CRB and Apple(树状数组+dp)
- hdu 5406 CRB and Apple
- hdu 5406CRB and Apple
- HDU 5406 CRB and Apple
- 【DP】 HDOJ 5410 CRB and His Birthday
- [HDU 5406] CRB and Apple (双线程DP+树状数组)
- HDOJ 5410 CRB and His Birthday DP背包
- 【HDOJ 1009】 CRB and String
- HDOJ 5409 CRB and Graph
- HDOJ 5416 CRB and Tree
- HDU 5406 CRB and Apple (2015 Multi-University Training Contest 10)
- hdu 5406 CRB and Apple, 2015多校联合训练赛,费用流
- hdu 5406 CRB and Apple 求两个不相交的不下降子序列之和最大
- 【HDOJ 1005】 CRB and His Birthday
- 【数论】 HDOJ 5407 CRB and Candies
- HDOJ 5414 CRB and String 模拟
- java获取文件md5值
- hdu 5407 CRB and Candies 2015多校联合训练赛#10 找规律 素数筛法
- Mysql删除多表及多表记录sql语句
- wenti
- tomcat 虚拟目录配置
- 【DP】 HDOJ 5406 CRB and Apple
- thinkphp 类库扩展
- 修改WampServer的默认端口
- 图片翻转效果的实现
- C语言的static和extern关键字的使用
- 通过jQuery的Ajax方式来提交Form表单
- poj 2632 Crashing Robots
- 蘑菇街内推面试经验
- MySql查询总结