To Miss Our Children Time(dp)

Posted handsomecui

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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\n", ans);
    }
    return 0;
}

 

以上是关于To Miss Our Children Time(dp)的主要内容,如果未能解决你的问题,请参考以下文章

递归过滤对象数组

SpringUnable to start ServletWebServerApplicationContext due to miss ServletWebServerFactory bean(代码

[Cycle.js] Hyperscript as our alternative to template languages

Our ultimate guide to Tianjin (in a day trip)

__twice,the postman refused to deliver our letters unless we chained our dog up.

Photography has opened our eyes to a multitude of beauty