[UVA437] The Tower of Babylon

描述

UVA437

思路

每种长方体可重复使用, 而每种长方体有六种摆放方式,所以可以将每个可随机摆放长方体视为摆放方式固定的六个长方体。
对于与长方体的堆叠,考虑上下长方体的x, y , 所以可以将长方体按x降序排列。	然后就是动态规划问题.

题解

#include <algorithm>
#include <string>
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <stack>
int dp[200];
struct Rec {
	int a, b, c;
	Rec() = default;
	Rec(int a, int b, int c) : a(a), b(b), c(c) {}
	bool operator < (const Rec &rec) const
	{
		if (a < rec.a)
			return true;
		else if (a > rec.a)
			return false;
		else
		{
			if (b < rec.b)
				return true;
			else if (b > rec.b)
				return false;
			else
			{
				return c < rec.c;
			}
		}
	}
}rec[200];

int main()
{
	int cases = 0;
	int t;
	while (scanf("%d", &t), t)
	{
		cases++;
		int cnt = 0;
		for (int i = 0; i < t; i++)
		{
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			rec[cnt++] = Rec(a, b, c);
			rec[cnt++] = Rec(a, c, b);
			rec[cnt++] = Rec(b, a, c);
			rec[cnt++] = Rec(b, c, a);
			rec[cnt++] = Rec(c, a, b);
			rec[cnt++] = Rec(c, b, a);
		}
		std::sort(std::begin(rec), std::begin(rec) + cnt);
		for (int i = 0; i < cnt; i++)
			dp[i] = rec[i].c;
		for (int i = 1; i < cnt; i++)
			for (int j = 0; j < i; j++)
				if (rec[i].a > rec[j].a && rec[i].b > rec[j].b)
					dp[i] = std::max(dp[i], dp[j] + rec[i].c);
		printf("Case %d: maximum height = %d\n", t, *std::max_element(std::begin(dp), std::begin(dp) + cnt));
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值