hdu1069

http://acm.hdu.edu.cn/showproblem.php?pid=1069

dp  dp[i]={max(a[i],a[i]+dp[j]),j<i}

/*************************************************************************
	> File Name: main.cpp
	> Author: huangshuai
	> Mail: [email protected] 
	> Created Time: Wed 13 Mar 2013 02:59:10 PM CST
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct block
{
	int x,y,z;
	int dp;
};
block a[500];
bool cmp(block a,block b)
{
	if(a.x!=b.x)
		return a.x>b.x;
	else
		return a.y>b.y;
}
int main()
{
	int n;
	int s=0;
	while(scanf("%d",&n),n!=0)
	{
		int i;
		int k=0;
		memset(a,0,sizeof(a));
		for(i=0;i<n;i++)
		{
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			a[k].x=x,a[k].y=y,a[k].z=a[k].dp=z,k++;
			a[k].x=x,a[k].y=z,a[k].z=a[k].dp=y,k++;
			a[k].x=y,a[k].y=x,a[k].z=a[k].dp=z,k++;
			a[k].x=y,a[k].y=z,a[k].z=a[k].dp=x,k++;
			a[k].x=z,a[k].y=x,a[k].z=a[k].dp=y,k++;
            a[k].x=z,a[k].y=y,a[k].z=a[k].dp=x,k++;
		}
		sort(a,a+k,cmp);
		int max=a[0].dp;
		int j;
		for(i=1;i<k;i++)
		{
			for(j=i-1;j>=0;j--)
			{
		 		if(a[j].x>a[i].x&&a[j].y>a[i].y&&(a[i].dp<a[j].dp+a[i].z))
				{
		 			a[i].dp=a[j].dp+a[i].z;
				}
				if(a[i].dp>max)
					max=a[i].dp;
			}

		}
		printf("Case %d: maximum height = %d\n",++s,max);
	}
}


你可能感兴趣的:(hdu1069)