这道题做了有两天了吧,今天才总算找到错误,本来我想了一种思路,一直wr,找错误一直找不到,今天下午吃过饭后和lky讨论了一下,才总算明白我的思路错在了哪里,看来,互相交流还是很有必要的啊。。。。。。。。。题目:
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?
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.
#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; }