题目:http://acm.hdu.edu.cn/showproblem.php?pid=1069
这个博客写得很好:https://blog.youkuaiyun.com/lttree/article/details/26606947
#include <bits/stdc++.h>
using namespace std;
int N,dp[205];
struct rec
{
int l,w,h;
}a[205];
bool cmp(rec a,rec b)
{
if(a.l==b.l)return a.w<b.w;
return a.l<b.l;
}
int main()
{
int cas=1;
while(~scanf("%d",&N)&&N)
{
int l,w,h,tol=0,ans=0;
for(int i=1;i<=N;i++)
{
scanf("%d%d%d",&l,&w,&h);
a[tol++]={l,w,h};
a[tol++]={l,h,w};
a[tol++]={w,l,h};
a[tol++]={w,h,l};
a[tol++]={h,l,w};
a[tol++]={h,w,l};
}
sort(a,a+tol,cmp);
memset(dp,0,sizeof(dp));
ans=dp[0]=a[0].h;
for(int i=1;i<tol;i++)
{
int maxx=0;
for(int j=0;j<i;j++)
{
if(a[j].l<a[i].l&&a[j].w<a[i].w)
maxx=max(dp[j],maxx);
}
dp[i]=maxx+a[i].h;
ans=max(ans,dp[i]);
}
printf("Case %d: maximum height = %d\n",cas++,ans);
}
return 0;
}