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吃$
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = ;
  4. int n,c[maxn][maxn],Li[maxn],tot;
  5. void add(int *T,int i,int val){
  6. while(i <= tot){
  7. T[i] = max(T[i],val);
  8. i += i&-i;
  9. }
  10. }
  11. int query(int *T,int i,int ret = ){
  12. while(i > ){
  13. ret = max(ret,T[i]);
  14. i -= i&-i;
  15. }
  16. return ret;
  17. }
  18. struct Apple{
  19. int h,d;
  20. bool operator<(const Apple &rhs)const{
  21. if(h == rhs.h) return d > rhs.d;
  22. return h < rhs.h;
  23. }
  24. }A[maxn];
  25. int main(){
  26. int kase;
  27. scanf("%d",&kase);
  28. while(kase--){
  29. scanf("%d",&n);
  30. memset(c,,sizeof c);
  31. for(int i = ; i < n; ++i){
  32. scanf("%d%d",&A[i].h,&A[i].d);
  33. Li[tot++] = A[i].d;
  34. }
  35. sort(Li,Li + tot);
  36. tot = unique(Li,Li + tot) - Li;
  37. sort(A,A+n);
  38. for(int i = ; i < n; ++i)
  39. A[i].d = tot - (lower_bound(Li,Li + tot,A[i].d)-Li);
  40. for(int i = ; i < n; ++i){
  41. memset(Li,,sizeof Li);
  42. for(int j = ; j <= tot; ++j)
  43. Li[j] = query(c[j],A[i].d) +;
  44. for(int j = ; j <= tot; ++j){
  45. add(c[j],A[i].d,Li[j]);
  46. add(c[A[i].d],j,Li[j]);
  47. }
  48. }
  49. int ret = ;
  50. for(int i = ; i <= tot; ++i)
  51. ret = max(ret,query(c[i],tot));
  52. printf("%d\n",ret);
  53. }
  54. return ;
  55. }

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. Codeforces444A_DZY Loves Physics

    DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. ZOJ 1654 Place the Robots(最大匹配)

    Robert is a famous engineer. One day he was given a task by his boss. The background of the task was ...

  3. UI 经常用法总结之--- UIWindow UIView (不断更新中)

     UIWindow (UIView) 1.创建一个uiwindow对象 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScr ...

  4. Java中static作用及使用方法具体解释

    1.1概述: static是静态修饰符,什么叫静态修饰符呢?大家都知道,在程序中不论什么变量或者代码都是在编译时由系统自己主动分配内存来存储的.而所谓静态就是指在编译后所分配的内存会一直存在.直到程序 ...

  5. POJ1179 Polygon 区间DP

    题目大意: 多边形游戏,有N个顶点的多边形,3 <= N <= 50 ,多边形有N条边,每个顶点中有一个数字(可正可负),每条边上或者是“+”号,或者是“*”号.边从1到N编号,首先选择一 ...

  6. 通用扩展函数之TypeParse

    代码实现: ".TryToInt();//转换为int失败返回0 var int2 = "2x".TryToInt(); );//转换为int失败返回1 ); " ...

  7. LightOJ--1149--Factors and Multiples(二分图好题)

    Factors and Multiples Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu ...

  8. [HDU 4261] Estimation

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4261 [算法] 首先,有一个结论 : | a[1] - k | + | a[2] - k | + ...

  9. Elasticsearch日志收集

    Install pip if necessary curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py&q ...

  10. lua中.和:的区别

    local myTable = {} function myTable:putMyname(val) print(val) print(self and self.name) end myTable. ...