Block (DP) issues

Source: Internet
Author: User

Question: Does remember our children time? When we were children, we were interesting in almost everything around ourselves. A little thing or a simple game would 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 is child. Here is the game Rules:there lies many blocks on the ground, little LLL wants build "skyscraper" using these blocks. There is three kinds of blocks signed by an integer d. We describe each block's shape is Cuboid using the four integers ai, bi, ci, di. AI, Bi is both edges of the block one of them is length and the other is width. CI is
Thickness of the block. We know that the CI must is vertical with earth ground. Di describe the kind of the block. When di = 0 The block's length and width must is 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 is more or equal to the block ' s length which lies under the block and width and the block ' s area must is more than the block's area which lies under the block. When di = 2 The block length and width must is more than the block ' s length and width which lies under the block. Here is 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 <=), 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

Answer: Test instructions is probably to give you some building blocks, divided into three categories, 0: can only be placed in less than equal to its length and width of the building blocks, 1: Can only be placed in the length and width of less than equal to it and less than the area of his wood, 2: can only be placed in the long and wide even smaller than its wood The highest height of the building blocks.

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace Std;
struct block
{
int x,y,z,d;
}B[1005];
Long Long dp[1005];
int n;
BOOL CMP (block A,block B)
{
if (a.x!=b.x) return a.x<b.x;
if (A.Y!=B.Y) return a.y<b.y;
Return a.d>b.d;
}
void DP ()
{
Long Long ans=b[0].z;
for (int i=0;i<n;i++)
{
Dp[i]=b[i].z;
Ans=max (Ans,dp[i]);
}
for (int i=1;i<n;i++)
{
if (b[i].d==0)
{
for (int j=0;j<i;j++)
{
if (B[J].X&LT;=B[I].X&AMP;&AMP;B[J].Y&LT;=B[I].Y)
Dp[i]=max (DP[I],DP[J]+B[I].Z);
}
}
if (b[i].d==1)
{
for (int j=0;j<i;j++)
{
if (b[j].x<=b[i].x&&b[i].y>=b[j].y&& (b[i].y*b[j].y| | b[i].x>b[j].x))
Dp[i]=max (DP[I],DP[J]+B[I].Z);
}
}
if (b[i].d==2)
{
for (int j=0;j<i;j++)
{
if (B[I].X&GT;B[J].X&AMP;&AMP;B[I].Y&GT;B[J].Y)
{
Dp[i]=max (DP[I],DP[J]+B[I].Z);
}
}
}
Ans=max (Ans,dp[i]);
}
cout<<ans<< ' \ n ';
}

int main ()
{
while (1)
{
scanf ("%d", &n);
if (n==0) break;
for (int i=0;i<n;i++)
{
scanf ("%d%d%d%d", &AMP;B[I].X,&AMP;B[I].Y,&AMP;B[I].Z,&AMP;B[I].D);
if (B[I].X&LT;B[I].Y)
Swap (B[I].X,B[I].Y);
}
Sort (b,b+n,cmp);
DP ();
}
return 0;
}

Block (DP) issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.