题意: 给你矩形的长宽高(有无限多个),问你嵌套矩形最多可以落多高思路:和矩形的嵌套差不多 ,,不多说了 ,看代码把
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node
{
int x,y,z;
}edg[33*4];
int dp[33*4];
bool cmp(node a,node b)
{
if(a.x == b.x)
{
return a.y<b.y;
}
else
{
return a.x<b.x;
}
}
int main()
{
int n;
int te = 0 ;
while(scanf("%d",&n)!=EOF)
{
if(n == 0) break;
++te;
int a,b,c;
int cnt = 1 ;
for(int i = 1 ; i <= n; i ++)
{
scanf("%d%d%d",&a,&b,&c);
edg[cnt].x = a,edg[cnt].y = b,edg[cnt].z = c; //a b c
cnt++;
edg[cnt].x = a,edg[cnt].y = c,edg[cnt].z = b;
cnt++;
edg[cnt].x = b,edg[cnt].y = a , edg[cnt].z = c;
cnt++;
edg[cnt].x = b,edg[cnt].y = c , edg[cnt].z = a;
cnt++;
edg[cnt].x = c,edg[cnt].y = a , edg[cnt].z = b;
cnt++;
edg[cnt].x = c,edg[cnt].y = b , edg[cnt].z = a;
cnt++;
}
sort(edg+1,edg+cnt,cmp);
memset(dp,0,sizeof(dp));
int ans = 0 ;
for(int i = 1 ; i <cnt ; i++)//当前状态
{
int maxn = 0;
for(int j = 1 ; j <=i ;j++)//可以转移的状态
{
if(edg[i].x>edg[j].x&&edg[i].y>edg[j].y)//如果可以转移的话
{
maxn = max(dp[j]+edg[i].z,maxn);//最大值,等于可以转移的状态的最大值加上当前状态的最大值。
}
}
dp[i] = maxn;
if(dp[i] == 0)
{
dp[i] = edg[i].z;//这里如果没有被更新,就把dp[i] 的状态赋值为他自己
}
if(dp[i]>ans)
{
ans = dp[i];
}
}
printf("Case %d: maximum height = %d\n",te,ans);
}
}