2015
04-14

# To Miss Our Children Time

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?

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.

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.

3
10 10 12 0
10 10 12 1
10 10 11 2
2
10 10 11 1
10 10 11 1
0

24
11

 Run ID Submit Time Judge Status Pro.ID Exe.Time Exe.Memory Code Len. Language Author 4597349 2011-09-14 01:42:20 Accepted 4001 46MS 324K 1227 B G++ xym2010
#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<=b[i].x&&b[j].y<=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>b[j].x&&b[i].y>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",&b[i].x,&b[i].y,&b[i].z,&b[i].d);
if(b[i].x<b[i].y)
swap(b[i].x,b[i].y);
}
sort(b,b+n,cmp);
DP();
}
return 0;
}

1. 我希望结局是：李小沫帮助肆海沙追张小菲，虽然最后失败了，但在过程中喜欢上了对方，而颍亮知道了张小菲的身份后，灰常高兴但张小菲拒绝了颍亮的帮助………….而李小沫也走上了梦想之路

2. 我希望结局是：李小沫帮助肆海沙追张小菲，虽然最后失败了，但在过程中喜欢上了对方，而颍亮知道了张小菲的身份后，灰常高兴但张小菲拒绝了颍亮的帮助………….而李小沫也走上了梦想之路

3. 我希望结局是：李小沫帮助肆海沙追张小菲，虽然最后失败了，但在过程中喜欢上了对方，而颍亮知道了张小菲的身份后，灰常高兴但张小菲拒绝了颍亮的帮助………….而李小沫也走上了梦想之路

4. 我希望结局是：李小沫帮助肆海沙追张小菲，虽然最后失败了，但在过程中喜欢上了对方，而颍亮知道了张小菲的身份后，灰常高兴但张小菲拒绝了颍亮的帮助………….而李小沫也走上了梦想之路

5. 我希望结局是：李小沫帮助肆海沙追张小菲，虽然最后失败了，但在过程中喜欢上了对方，而颍亮知道了张小菲的身份后，灰常高兴但张小菲拒绝了颍亮的帮助………….而李小沫也走上了梦想之路

6. 我希望结局是：李小沫帮助肆海沙追张小菲，虽然最后失败了，但在过程中喜欢上了对方，而颍亮知道了张小菲的身份后，灰常高兴但张小菲拒绝了颍亮的帮助………….而李小沫也走上了梦想之路

7. 我还有个问题想请教一下，就是感觉对于新手来说，递归理解起来有些困难，不知有没有什么好的方法或者什么好的建议？

8. 有一点问题。。后面动态规划的程序中
int dp[n+1][W+1];
会报错 提示表达式必须含有常量值。该怎么修改呢。。