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


    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 = 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
    ",ret);
    53     }
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    django框架——十二
    django框架——十一
    请简述一下你所了解的数据源控件有哪些
    在ASP.NET中,<%= %>和<%# %>有什么区别
    请解释ASP.NET中的web页面与其隐藏类之间的关系
    什么是viewstate,能否禁用?是否所用控件都可以禁用
    WEB控件及HTML服务端控件能否调用客户端方法?如果能,请解释如何调用
    静态类和静态方法的好处
    请写出在ASP.NET中常用的几种页面间传值的方法,并说出它们的特点。
    连接数据库主要有哪几个对象
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4758915.html
Copyright © 2020-2023  润新知