• To Miss Our Children Time(dp)


    To Miss Our Children Time

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
    Total Submission(s): 4502    Accepted Submission(s): 1224


    Problem Description
    Do you remember our children time? When we are children, we are interesting in almost everything around ourselves. A little thing or a simple game will brings us lots of happy time! LLL is a nostalgic boy, now he grows up. In the dead of night, he often misses something, including a simple game which brings him much happy when he was child. Here are the game rules: There lies many blocks on the ground, little LLL wants build "Skyscraper" using these blocks. There are three kinds of blocks signed by an integer d. We describe each block's shape is Cuboid using four integers ai, bi, ci, di. ai, bi are two edges of the block one of them is length the other is width. ci is 
    thickness of the block. We know that the ci must be vertical with earth ground. di describe the kind of the block. When di = 0 the block's length and width must be more or equal to the block's length and width which lies under the block. When di = 1 the block's length and width must be more or equal to the block's length which lies under the block and width and the block's area must be more than the block's area which lies under the block. When di = 2 the block length and width must be more than the block's length and width which lies under the block. Here are some blocks. Can you know what's the highest "Skyscraper" can be build using these blocks?
     
    Input
    The input has many test cases. 
    For each test case the first line is a integer n ( 0< n <= 1000) , the number of blocks. 
    From the second to the n+1'th lines , each line describing the i‐1'th block's a,b,c,d (1 =< ai,bi,ci <= 10^8 , d = 0 or 1 or 2). 
    The input end with n = 0.
     
    Output
    Output a line contains a integer describing the highest "Skyscraper"'s height using the n blocks.
     
    Sample Input
    3 10 10 12 0 10 10 12 1 10 10 11 2 2 10 10 11 1 10 10 11 1 0
     
    Sample Output
    24 11
     
    Source
    题解:当时没细想,就是个很水的dp。。。1000两重for,注意long long;
    代码:
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<vector>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    const int MAXN = 1010;
    typedef long long LL;
    struct Node{
        int w, h, c, d;
        void init(){
            scanf("%d%d%d%d", &w, &h, &c, &d);
            if(w > h){
                swap(w, h);
            }
        }
        friend bool operator < (Node a, Node b){
            if(a.h != b.h)
                return a.h < b.h;
            if(a.w !=  b.w)
                return a.w < b.w;
            return a.d > b.d;
        }
    };
    Node dt[MAXN];
    LL dp[MAXN];
    bool js(Node a, Node b){
        if(b.d == 2 && a.w < b.w && a.h < b.h)
            return true;
        else if(b.d == 1 && a.w <= b.w && a.h <= b.h && (a.w < b.w || a.h < b.h))
            return true;
        else if(b.d == 0 && a.w <= b.w && a.h <= b.h)
            return true;
        return false;
    }
    int main(){
        int n;
        while(~scanf("%d", &n), n){
            for(int i = 0; i < n; i++){
                dt[i].init();
            }
            sort(dt, dt + n);
            memset(dp, 0, sizeof(dp));
            LL ans = 0;
            for(int i = 0; i < n; i++){
                  dp[i] = dt[i].c;
                for(int j = 0; j < i; j++){
                    if(js(dt[j], dt[i]))
                        dp[i] = max(dp[i], dp[j] + dt[i].c);
                }
                ans = max(ans, dp[i]);
            }
            printf("%lld
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    【FLASH BUILDER 4.6 快捷键】只记几个对自己有帮助的
    分享一个消息组件
    一些iis配置相关报错的参考
    JQuery 学习总结及实例
    百度地图 测距
    VS2010引用App_Code下的类文件问题解决方法
    HttpWebRequest 方式提交文件数据以图片为例
    Flex与.NET互操作(二):基于WebService的数据访问(上)
    Asp.net MVC中的ViewData与ViewBag
    C# HttpWebRequest 方式提交数据,参数为普通键值对
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5523245.html
Copyright © 2020-2023  润新知