ZOJ 1093 Monkey and Banana【DP】

94 篇文章 0 订阅
24 篇文章 0 订阅
//2630234 	2011-08-16 20:29:30 	Accepted 	1093 	C++ 	0 	180 	ylwh@Unknown
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define N 31
struct node
{
	int x, y, z;
}s[N*3];
int cmp(struct node a, struct node b)
{
	if(a.x != b.x)
		return a.x < b.x;
	else if(a.y != b.y)
		return a.y <b.y;
}
int main()
{
	int n, i, j, t=0, cnt, a, b, c, h[3*N], ans;
	while(scanf("%d", &n), n)
	{
		cnt = -1;
		t++;
		for(i=0; i<n; i++)
		{
			scanf("%d%d%d", &a, &b, &c);
			s[++cnt].x = a < b ? a : b;
			s[cnt].y = a > b ? a : b;
			s[cnt].z = c;
			s[++cnt].x = a < c ? a : c;
			s[cnt].y = a > c ? a : c;
			s[cnt].z = b;
			s[++cnt].x = b < c ? b : c;
			s[cnt].y = b > c ? b : c;
			s[cnt].z = a;
		}
		sort(s, s+cnt+1, cmp);
		ans = 0;
		for(i=0; i<=cnt; i++)
		{
			h[i] = s[i].z;
			for(j=0; j<i; j++)
				if(s[j].x < s[i].x && s[j].y < s[i].y)
					if(h[j] + s[i].z > h[i])
						h[i] = h[j] + s[i].z;
			if(h[i] > ans)
				ans = h[i];
		}
		printf("Case %d: maximum height = %d\n", t, ans);
	}
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值