HDU 1069
#include<bits/stdc++.h>
#define M 10000
using namespace std;
struct rectangle{
int l,w,h;
}rec[M];
int dp[M];
bool cmp(rectangle a, rectangle b)
{
if(a.l == b.l) return a.w < b.w;
else return a.l < b.l;
}
int main()
{
int n,J = 1;
while(scanf("%d",&n) != EOF && n)
{
int len = 0,x,y,z,maxn = 0;
for(int i = 0; i < n; i++)
{
scanf("%d%d%d",&x,&y,&z);
rec[len].l = x; rec[len].w = y; rec[len++].h = z;
rec[len].l = x; rec[len].w = z; rec[len++].h = y;
rec[len].l = y; rec[len].w = x; rec[len++].h = z;
rec[len].l = y; rec[len].w = z; rec[len++].h = x;
rec[len].l = z; rec[len].w = y; rec[len++].h = x;
rec[len].l = z; rec[len].w = x; rec[len++].h = y;
}
sort(rec,rec+len,cmp);
for(int i = 0; i < len; i++)
{
int MM = 0;
for(int j = 0; j < i; j++)
{
if(rec[j].l < rec[i].l && rec[j].w < rec[i].w)
dp[i] = max(MM,dp[j])+rec[i].h;maxn = max(maxn,dp[i]);
}
}
cout<<"Case "<<J<<": maximum height = "<<maxn<<endl;
J++;
}
return 0;
}
排列最多180种,每种都拿出来比较就行。

浙公网安备 33010602011771号