码迷,mamicode.com
首页 > 移动开发 > 详细

2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple

时间:2015-08-25 23:23:32      阅读:331      评论:0      收藏:0      [点我收藏+]

标签:

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
 
解题:
 
技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 2010;
 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 = 0){
12     while(i > 0){
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,0,sizeof c);
31         for(int i = 0; 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 = 0; i < n; ++i)
39          A[i].d = tot - (lower_bound(Li,Li + tot,A[i].d)-Li);
40         for(int i = 0; i < n; ++i){
41             memset(Li,0,sizeof Li);
42             for(int j = 1; j <= tot; ++j)
43                 Li[j] = query(c[j],A[i].d) +1;
44             for(int j = 1; 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 = 0;
50         for(int i = 1; i <= tot; ++i)
51             ret = max(ret,query(c[i],tot));
52         printf("%d\n",ret);
53     }
54     return 0;
55 }
View Code

 

2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4758915.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!