hdu4001

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

The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest

*************************************************************************

这是2011年大连赛区网络赛的第一道题目。当时有YYB在写了,我就没写。

这题就是一道简单dp。先把每个木块存一下,然后按照先a从小到大,在按照b从小到大,再按照d从大到小排列。具体的状态转移方程是一样的,只是当d有差别的时候,j的取值有所不同,dp[i]=max{dp[j]+c[i]}(j是比i小的,且满足d的要求的木块)。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct node
{
 __int64 a,b,c,d;
} p[1005];
int n;
__int64 dp[1005];

bool cmp(node a,node b)
{
    if(a.a!=b.a)return a.a<b.a;
    if(a.b!=b.b)return a.b<b.b;
    return a.d>b.d;
}
int main()
{
    int i,j;
    while(scanf("%d",&n),n)
    {
        memset(dp,0,sizeof(dp));
        for(i=1; i<=n; i++)
        {
            scanf("%I64d%I64d%I64d%I64d",&p[i].a,&p[i].b,&p[i].c,&p[i].d);
            if(p[i].a<p[i].b)
            {
                int64_t t=p[i].a;
                p[i].a=p[i].b;
                p[i].b=t;
            }
        }
        sort(p+1,p+1+n,cmp);
        p[0].a=p[0].b=p[0].c=p[0].d=0;
        for(i=1; i<=n; i++)
            for(j=i-1; j>=0; j--)
            {
                if(p[i].d==0&&p[i].a>=p[j].a&&p[i].b>=p[j].b)
                    dp[i]=max(dp[i],dp[j]+p[i].c);
                if(p[i].d==1&&p[i].a>=p[j].a&&p[i].b>=p[j].b&&p[i].a*p[i].b>p[j].a*p[j].b)
                    dp[i]=max(dp[i],dp[j]+p[i].c);
                if(p[i].d==2&&p[i].a>p[j].a&&p[i].b>p[j].b)
                    dp[i]=max(dp[i],dp[j]+p[i].c);
            }
        __int64 Max=-1;
        for(i=1; i<=n; i++)
            if(dp[i]>Max)Max=dp[i];
        printf("%I64d\n",Max);
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值