【hdoj 4001】To Miss Our Children Time

来源:互联网 发布:自动化编程软件有哪些 编辑:程序博客网 时间:2024/05/16 23:40
To Miss Our Children Time
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 4216 Accepted Submission(s): 1101


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

题意理解:堆砖块,标号为0 的砖块的长和宽要大于等于它下面的砖块的长和宽;标号为1 的砖的长和宽要大于等于它下面的砖块的长和宽,并且它的面积要大于下面砖块的面积;标号为2 的砖块的长和宽要大于它下面的长和宽;问:求出能堆出的最大高度。

输入:有多组数据,每组数据首先输入n,代表有n个砖块,然后接下来的n行,每行四个数字,分别为砖块的长,宽,高,标号。


解题思路:dp题,还算基本的难度吧,主要是将数据排序,保证能放在第i个砖块的砖块都排在第i个砖块之前。那么第i个砖块作为“摩天大楼”最上面的砖,它的高度就是i之前的最大高度+i块砖块的厚度。

 code:

#include <iostream>#include <cstdio>#include <algorithm>#include <string.h>using namespace std;int n;struct node{    long long a,b,c;    long long s;    int d;}block[1005];long long dp[1005];int cmp(node b1,node b2){    if(b1.a==b2.a)    {        if(b1.b==b2.b)            return b1.d>b2.d;        return b1.b<b2.b;    }    return b1.a<b2.a;}int main(){    long long cmx;    long long  a,b;    while(scanf("%d",&n)!=EOF&&n)    {        for(int i=1;i<=n;i++)        {            scanf("%I64d%I64d%I64d%d",&a,&b,&block[i].c,&block[i].d);            block[i].a = a>b?a:b;            block[i].b = a<b?a:b;            block[i].s = a*b;        }        sort(block+1,block+n+1,cmp);        for(int i=1;i<=n;i++)            dp[i]=block[i].c;        for(int i=2;i<=n;i++)        {            cmx=0;            if(block[i].d==2)            {                for(int j=1;j<i;j++)                {                    if(block[j].a<block[i].a&&block[j].b<block[i].b&&cmx<dp[j])                        cmx = dp[j];                }            }            else if(block[i].d==1)            {                for(int j=1;j<i;j++)                {                    if(block[j].a<=block[i].a&&block[j].b<=block[i].b&&block[j].s<block[i].s&&cmx<dp[j])                        cmx=dp[j];                }            }            else            {                for(int j=1;j<i;j++)                {                    if(block[j].a<=block[i].a&&block[j].b<=block[i].b&&cmx<dp[j])                        cmx=dp[j];                }            }            dp[i]=cmx+block[i].c;        }        cmx=0;        for(int i=1;i<=n;i++)            if(cmx<dp[i])                cmx = dp[i];        printf("%I64d\n",cmx);    }    return 0;}

                                    


0 0
原创粉丝点击