hdu1069 Monkey and Banana DP 最大不降子序列的扩展

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

struct point
{
	int x,y,z;
	int area;
}b[200];

bool compare(point c,point d){ return c.area<d.area;}
int cmp(point c,point d){
	if((c.x>d.x && c.y>d.y)||(c.x>d.y && c.y>d.x))
		return 1;
	else
		return 0;
}

int main()
{
	int a[4],dir[3][3]={{0,1,2},{1,2,0},{0,2,1}},n,i,j,num,sum[200],m=0;
	while(scanf("%d",&n) , n){
		num=0;
		memset(sum,0,sizeof(sum));
		for(i=0;i<n;i++){
			scanf("%d%d%d",&a[0],&a[1],&a[2]);

			for(j=0;j<3;j++){
				b[num].x=a[dir[j][0]];
				b[num].y=a[dir[j][1]];
				b[num].z=a[dir[j][2]];
				b[num].area=b[num].x*b[num].y;
				num++;
			}
		}

		sort(b,b+num,compare);
		
		sum[0]=b[0].y;
		for(i=0;i<3*n;i++){
			int temp=0;
			for(j=0;j<i;j++){
				if(sum[j]>temp && cmp(b[i],b[j])){
					temp=sum[j];
				}
			}
			sum[i]=temp+b[i].z;
		}
		
		int max=-1;
		for(i=0;i<3*n;i++)
			if(max<sum[i])
				max=sum[i];

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

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值