CRB and Apple

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 421    Accepted Submission(s): 131

Problem Description

In Codeland there are many apple trees.
One day CRB and his girlfriend decided to eat all apples of one tree.
Each apple on the tree has height and deliciousness.
They decided to gather all apples from top to bottom, so an apple can be gathered only when it has equal or less height than one just gathered before.
When an apple is gathered, they do one of the following actions.
1. CRB eats the apple.
2. His girlfriend eats the apple.
3. Throw the apple away.
CRB(or his girlfriend) can eat the apple only when it has equal or greater deliciousness than one he(she) just ate before.
CRB wants to know the maximum total number of apples they can eat.
Can you help him?

Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains a single integer N denoting the number of apples in a tree.
Then N lines follow, i-th of them contains two integers Hi and Di indicating the height and deliciousness of i-th apple.
1 ≤ T ≤ 48
1 ≤ N ≤ 1000
1 ≤ Hi, Di ≤ 109

Output
For each test case, output the maximum total number of apples they can eat.

Sample Input
1
5
1 1
2 3
3 2
4 3
5 1

Sample Output
4

Author
KUT(DPRK)

Source
 
解题:
 $求两个不交的LIS,他们的长度和最长$
$dp[i][j]表示两个序列一个以i结尾,一个以j结尾,那么有转移方程dp[i][j]=max(dp[k][j],dp[j][k])+1,k < i$
$表示当前苹果被A吃,或者被B吃$
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int n,c[maxn][maxn],Li[maxn],tot;
void add(int *T,int i,int val){
while(i <= tot){
T[i] = max(T[i],val);
i += i&-i;
}
}
int query(int *T,int i,int ret = ){
while(i > ){
ret = max(ret,T[i]);
i -= i&-i;
}
return ret;
}
struct Apple{
int h,d;
bool operator<(const Apple &rhs)const{
if(h == rhs.h) return d > rhs.d;
return h < rhs.h;
}
}A[maxn];
int main(){
int kase;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
memset(c,,sizeof c);
for(int i = ; i < n; ++i){
scanf("%d%d",&A[i].h,&A[i].d);
Li[tot++] = A[i].d;
}
sort(Li,Li + tot);
tot = unique(Li,Li + tot) - Li;
sort(A,A+n);
for(int i = ; i < n; ++i)
A[i].d = tot - (lower_bound(Li,Li + tot,A[i].d)-Li);
for(int i = ; i < n; ++i){
memset(Li,,sizeof Li);
for(int j = ; j <= tot; ++j)
Li[j] = query(c[j],A[i].d) +;
for(int j = ; j <= tot; ++j){
add(c[j],A[i].d,Li[j]);
add(c[A[i].d],j,Li[j]);
}
}
int ret = ;
for(int i = ; i <= tot; ++i)
ret = max(ret,query(c[i],tot));
printf("%d\n",ret);
}
return ;
}

2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple的更多相关文章

  1. 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries

    CRB and Queries Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  2. 2015 Multi-University Training Contest 10 hdu 5411 CRB and Puzzle

    CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  3. 2015 Multi-University Training Contest 10 hdu 5407 CRB and Candies

    CRB and Candies Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. 2016 Multi-University Training Contest 10 || hdu 5860 Death Sequence(递推+单线约瑟夫问题)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 题目大意:给你n个人排成一列编号,每次杀第一个人第i×k+1个人一直杀到没的杀.然后 ...

  5. 2016 Multi-University Training Contest 10 [HDU 5861] Road (线段树:区间覆盖+单点最大小)

    HDU 5861 题意 在n个村庄之间存在n-1段路,令某段路开放一天需要交纳wi的费用,但是每段路只能开放一次,一旦关闭将不再开放.现在给你接下来m天内的计划,在第i天,需要对村庄ai到村庄bi的道 ...

  6. HDU - 5406 CRB and Apple (费用流)

    题意:对于给定的物品,求两个在高度上单调不递增,权值上单调不递减的序列,使二者长度之和最大. 分析:可以用费用流求解,因为要求长度和最大,视作从源点出发的流量为2的费用流,建负权边,每个物品只能取一次 ...

  7. hdu 5416 CRB and Tree(2015 Multi-University Training Contest 10)

    CRB and Tree                                                             Time Limit: 8000/4000 MS (J ...

  8. 2015 Multi-University Training Contest 10(9/11)

    2015 Multi-University Training Contest 10 5406 CRB and Apple 1.排序之后费用流 spfa用stack才能过 //#pragma GCC o ...

  9. 2016 Multi-University Training Contest 10

    solved 7/11 2016 Multi-University Training Contest 10 题解链接 分类讨论 1001 Median(BH) 题意: 有长度为n排好序的序列,给两段子 ...

随机推荐

  1. Spring技术内幕:SpringIOC原理学习总结

    前一段时候我把Spring技术内幕的关于IOC原理一章看完,感觉代码太多,不好掌握,我特意又各方搜集了一些关于IOC原理的资料,特加深一下印象,以便真正掌握IOC的原理. IOC的思想是:Spring ...

  2. 安卓实现序列化之Parcelable接口

    安卓实现序列化之Parcelable接口 1.实现序列化的方法: Android中实现序列化有两个选择:一是实现Serializable接口(是JavaSE本身就支持的) .一是实现Parcelabl ...

  3. JSTL函数标签

    tld 文件代码 <?xml version="1.0" encoding="UTF-8" ?> <taglib xmlns="ht ...

  4. Odoo(OpenERP)开发实践:数据模型学习

    作者:苏州-微尘 Odoo中,在Python类里定义的模型及字段信息,可在系统中直接查看.为用户开启技术特性权限后,就可以通过菜单 [设置->技术->数据结构->模型] 进入列表视图 ...

  5. 最长公共子序列 nlogn

    先来个板子 #include<bits/stdc++.h> using namespace std; , M = 1e6+, mod = 1e9+, inf = 1e9+; typedef ...

  6. tensorflow利用预训练模型进行目标检测(四):检测中的精度问题以及evaluation

    一.tensorflow提供的evaluation Inference and evaluation on the Open Images dataset:https://github.com/ten ...

  7. nyoj--239--月老的难题(最小点覆盖)

    月老的难题 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 月老准备给n个女孩与n个男孩牵红线,成就一对对美好的姻缘. 现在,由于一些原因,部分男孩与女孩可能结成幸福的一 ...

  8. 分布式系统CAP原则与BASE思想

    一.CAP原则 CAP原则又称CAP定理,指的是在一个分布式系统中, Consistency(一致性). Availability(可用性).Partition tolerance(分区容错性),三者 ...

  9. 利用ajax,canvas实现的测试php程序占用内存的代码

    receive.php <?php $array["time"]=time();$array["memory"]=memory_get_usage();e ...

  10. WEBGL学习笔记(七):实践练手1-飞行类小游戏之游戏控制

    接上一节,游戏控制首先要解决的就是碰撞检测了 这里用到了学习笔记(三)射线检测的内容了 以鸟为射线原点,向前.上.下分别发射3个射线,射线的长度较短大概为10~30. 根据上一节场景的建设,我把y轴设 ...