hdu1069Monkey and banana -最大递增子序列dp

#include<iostream>
using namespace std;

struct BOX
{
	int l,w,h;
}box[200];

int dp[200];

bool cmp(BOX a,BOX b)
{
	if(a.l==b.l)
		return a.w>b.w;
	else
		return a.l>b.l;
}

int main()
{
	int T=1,n,N,i,j,k;
	while(scanf("%d",&n),n)
	{
		N=6*n;
		for(i=1;i<=N;i+=6)
		{
			scanf("%d%d%d",&box[i].l,&box[i].w,&box[i].h);
			box[i+1].l=box[i].w;box[i+1].w=box[i].l;box[i+1].h=box[i].h;
			
			box[i+2].l=box[i].w;box[i+2].w=box[i].h;box[i+2].h=box[i].l;
			box[i+3].l=box[i+2].w;box[i+3].w=box[i+2].l;box[i+3].h=box[i+2].h;
			
			box[i+4].l=box[i].h;box[i+4].w=box[i].l;box[i+4].h=box[i].w;
			box[i+5].l=box[i+4].w;box[i+5].w=box[i+4].l;box[i+5].h=box[i+4].h;
		}
		
		sort(box+1,box+1+N,cmp);
	
		for(i=1;i<=N;i++)	dp[i]=box[i].h;
		for(i=2;i<=N;i++)
			for(j=1;j<i;j++)
				if(box[j].l>box[i].l&&box[j].w>box[i].w&&dp[i]<dp[j]+box[i].h)
					dp[i]=dp[j]+box[i].h;
		
		for(dp[0]=-1,i=1;i<=N;i++)
			if(dp[0]<dp[i])	dp[0]=dp[i];
		printf("Case %d: maximum height = %d\n",T++,dp[0]);
	}
	return 0;
}


你可能感兴趣的:(hdu1069Monkey and banana -最大递增子序列dp)