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;
    }
  • 相关阅读:
    分析facebook的AsyncDisplayKit框架,async-display使用async-transaction
    自制反汇编逆向分析工具 迭代第四版本
    自制反汇编逆向分析工具 迭代第三版本
    自制反汇编逆向分析工具 迭代第二版本
    分析facebook的AsyncDisplayKit框架中的Transaction的工作原理
    Oracle索引知识学习笔记
    PDF文件添加二维码水印教程
    图片添加二维码水印教程
    CAS单点登录之支持数据库认证
    CAS单点登录之服务端部署
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5523245.html
Copyright © 2011-2022 走看看