kuangbin专题十二 HDU1069 Monkey and Banana

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

题目大意:给出n种长方体的x,y,z(任意个),然后堆起来(要求严格小于自己下面的长方体),求能达到的最大高度。

经典的矩形嵌套:把每种长方体的6种方法都存储起来,然后排序,然后再像上升子序列dp一样。见注释

AC代码:

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define forn(i, x, n) for(int i = (x); i < n; i++)
#define nfor(i, x, n) for(int i = n-1; i >= x; i--)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF =0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-5;
const ll mod = 1e9+7;

struct node{
	int l, w, h;
}stu[200];
int dp[200];//dp[i] 表示 i能达到的最高高度 

bool cmp(node a, node b) {//先x 后 y 
	if(a.l == b.l)
		return a.w < b.w;
	return a.l < b.l;
}

int main() {
	int n, x, y, z, cur;
	int icase = 1;
	while(~scanf("%d", &n),n) {
		cur = 0;
		while(n--) {
			scanf("%d%d%d", &x, &y, &z);//存储6种状态 
			stu[cur].l = x; stu[cur].w = y; stu[cur++].h = z; 
			stu[cur].l = x; stu[cur].w = z; stu[cur++].h = y;
			stu[cur].l = y; stu[cur].w = z; stu[cur++].h = x;
			stu[cur].l = y; stu[cur].w = x; stu[cur++].h = z;
			stu[cur].l = z; stu[cur].w = x; stu[cur++].h = y;
			stu[cur].l = z; stu[cur].w = y; stu[cur++].h = x;
		}
		sort(stu, stu+cur, cmp);//排序 
		mem(dp, 0);
		int maxx = -inf;
		forn(i, 0, cur) {
			dp[i] = stu[i].h;//初始化 
			forn(j, 0, i) {//找到使自己最高的 
				if(stu[j].l < stu[i].l && stu[j].w < stu[i].w) {
					dp[i] = max(dp[j] + stu[i].h, dp[i]);
				}
			}
			maxx = max(maxx, dp[i]);//更新最高高度 
		}
		maxx = max(0, maxx);
		printf("Case %d: maximum height = %d\n", icase++, maxx);
	}
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值