这道题做了有两天了吧,今天才总算找到错误,本来我想了一种思路,一直wr,找错误一直找不到,今天下午吃过饭后和lky讨论了一下,才总算明白我的思路错在了哪里,看来,互相交流还是很有必要的啊。。。。。。。。。题目:
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
ac代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
struct block
{
_int64 len;
_int64 wid;
_int64 hi;
_int64 num;
}aa[1005];
bool cmp(block a,block b)
{
if(a.len==b.len)
{
if(a.wid==b.wid)
return a.num>b.num;
return a.wid<b.wid;
}
return a.len<b.len;
}
int main()
{
int n;
while(scanf("%d",&n))
{
if(n==0)
return 0;
int i,j;
_int64 a,b,dp[1005];
for(i=0;i<n;++i)
{
scanf("%I64d%I64d%I64d%I64d",&a,&b,&aa[i].hi,&aa[i].num);
if(a>b)
{aa[i].len=a;aa[i].wid=b;}
else
{aa[i].len=b;aa[i].wid=a;}
}
sort(aa,aa+n,cmp);
for(i=0;i<n;++i)
dp[i]=aa[i].hi;
_int64 mmax=dp[0];
for(i=1;i<n;++i)
{
for(j=0;j<i;++j)
{
if(aa[i].num==0)
{
if(aa[i].len>=aa[j].len&&aa[i].wid>=aa[j].wid&&dp[i]<aa[i].hi+dp[j])
dp[i]=dp[j]+aa[i].hi;
}
else if(aa[i].num==1)
{
if(aa[i].len>=aa[j].len&&aa[i].wid>=aa[j].wid&&(aa[i].len>aa[j].len||aa[i].wid>aa[j].wid)&&dp[i]<aa[i].hi+dp[j])
dp[i]=dp[j]+aa[i].hi;
}
else
{
if(aa[i].len>aa[j].len&&aa[i].wid>aa[j].wid&&dp[i]<aa[i].hi+dp[j])
dp[i]=dp[j]+aa[i].hi;
}
}
if(dp[i]>mmax)
mmax=dp[i];
}
printf("%I64d\n",mmax);
}
return 0;
}