zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    vue中判断APP 为ios系统 安卓系统 浏览器判断 微信 qq 支付宝
    vconsole调试工具使用
    vue 电话号中间四位****代替
    vue中使用倒计时
    在APP中ios输入账号和密码时键盘闪烁
    vue中返回随机数
    vue 阿里云的滑动验证
    从零开发一套完整的vue项目开发环境
    vue中修改第三方组件中的样式
    nginx 启动报错dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5523245.html
Copyright © 2011-2022 走看看