1,输入箱子的种类数
2,输入各个箱子的长宽高;
求各个箱子放起来达到的最大高度,要求,下面的箱子的长和宽都比上面的要大!!
#include"stdio.h"#include"stdlib.h"struct A{ int x; int y; int h;}each[100];int cmp(const void*a,const void*b) { struct A *c,*d; c=(struct A*)a; d=(struct A*)b; if(c->x!=d->x) return d->x-c->x; else return d->y-c->y; }int main(){ int n; int i,l; int k; int x,y,z; int dp[100]; int max; int Case=1; while(scanf("%d",&n),n) { k=0; for(i=0;iy?x:y; each[k].y=x>y?y:x; each[k].h=z; k++; each[k].x=x>z?x:z; each[k].y=x>z?z:x; each[k].h=y; k++; each[k].x=z>y?z:y; each[k].y=z>y?y:z; each[k].h=x; k++; } qsort(each,k,sizeof(each[0]),cmp); dp[0]=each[0].h; for(i=1;i =0;l--) { if((each[l].y>each[i].y&&each[l].x>each[i].x)||(each[l].y>each[i].x&&each[l].x>each[i].y)) { if(dp[l]>max) max=dp[l]; } } dp[i]=max+each[i].h; } max=0; for(i=0;i max) max=dp[i]; } printf("Case %d: maximum height = %d\n",Case,max); Case++; } return 0;}