Time Limit: 1000MS | | Memory Limit: 65768KB | | 64bit IO Format: %I64d & %I64u |
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
Hint
Source
The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest
//题意:
对于每块砖头输入四个参数,a,b,c,d,分别表示砖头的长宽高
d表示砖头的型号,
1、如果d==0时:上面的砖头的长和宽要大于等于它下面的砖头的长和宽
2、如果d==1时:上面的砖头的长和宽要大于等于它下面的砖头的长和宽,
并且上面的面积要大于下面的面积
3、如果d==2时:上面的砖头的长和宽要大于它下面的砖头的长和宽
现在问这n块砖头最高可以达到的高度
//思路:
直接排序模拟就行了
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define ll long long
#define N 1010
using namespace std;
struct zz
{
int w,l,h,d;
friend bool operator < (zz a,zz b)
{
if(a.l!=b.l)
return a.l<b.l;
if(a.w!=b.w)
return a.w<b.w;
return a.d>b.d;
}
}p[N];
ll dp[N];
bool judge(zz a,zz b)
{
if(b.d==2&&a.w<b.w&&a.l<b.l)
return true;
else if(b.d==1&&a.w<=b.w&&a.l<=b.l&&(a.w<b.w||a.l<b.l))
return true;
else if(b.d==0&&a.w<=b.w&&a.l<=b.l)
return true;
return false;
}
int main()
{
int n,i,j;
while(scanf("%d",&n),n)
{
memset(dp,0,sizeof(dp));
for(i=0;i<n;i++)
{
scanf("%d%d%d%d",&p[i].w,&p[i].l,&p[i].h,&p[i].d);
if(p[i].w>p[i].l)
{
int t=p[i].w;p[i].w=p[i].l;p[i].l=t;
}
}
sort(p,p+n);
ll ans=0;
for(i=0;i<n;i++)
{
dp[i]=p[i].h;
for(j=0;j<i;j++)
{
if(judge(p[j],p[i]))
dp[i]=max(dp[i],dp[j]+p[i].h);
}
ans=max(ans,dp[i]);
}
printf("%lld\n",ans);
}
return 0;
}