题目大意是给你一些方块的长宽高xyz,你可以无限使用并且可以旋转他们。
问你如何把它们堆得很高,一块堆上另一块的前提是下面那一块的长和宽都大于上面那一块。
很经典
下面是代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
struct po
{
int x,y,z;
};
po a[220];
bool cmp(po a,po b)
{
if(a.x==b.x) return a.y<=b.y;
else return a.x<b.x;
}
int h[220];
int main()
{
int n;
int kase = 1;
while(scanf("%d",&n) && n){
int m = 0;
for(int i=0,x,y,z;i<n;i++){
scanf("%d%d%d",&x,&y,&z);
a[m].x = x , a[m].y = y , a[m].z = z;
m++;
a[m].x = x , a[m].y = z , a[m].z = y;
m++;
a[m].x = z , a[m].y = y , a[m].z = x;
m++;
a[m].x = z , a[m].y = x , a[m].z = y;
m++;
a[m].x = y , a[m].y = x , a[m].z = z;
m++;
a[m].x = y , a[m].y = z , a[m].z = x;
m++;
}
sort(a,a+m,cmp);
memset(h,0,sizeof(h));
int ans = 0;
for(int i=0;i<m;i++) {h[i] = a[i].z;ans = max(ans,h[i]);}
for(int i=0;i<m;i++){
for(int j=0;j<=i;j++){
if(a[j].x < a[i].x && a[j].y < a[i].y && h[i]<h[j]+a[i].z){
h[i] = h[j] + a[i].z;
ans = max(ans,h[i]);
}
}
}
printf("Case %d: maximum height = ",kase++);
printf("%d\n",ans);
}
}