hdu1069 Monkey and Banana

本文探讨了如何使用动态规划解决砖块堆叠问题,通过分析不同方向的堆叠方式来最大化堆积高度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


#include <stdio.h>
#include <string.h>
#define INF 9999999

int box[102][3],height[102];
int number;//砖块总数3*n+1

void oriente(int index,int a,int b,int c)
{//(a,b)是底面,c是高
	box[index][0]=a;
	box[index][1]=b;
	box[index][2]=c;
}

int DP(int index)
{
	int i,ret=0;
	if(height[index]!=-1)
		return height[index];
	if(index>number)
		return 0;
	for(i=1;i<=number;++i)
	{
		if((box[index][0]>box[i][0]&&box[index][1]>box[i][1])
			||(box[index][0]>box[i][1]&&box[index][1]>box[i][0]))
			ret=DP(i)+box[i][2];
		if(ret>height[index])
			height[index]=ret;
	}
	return height[index];
}

int main()
{
	int i,n,a,b,c,cases=1;
	while(scanf("%d",&n)&&n)
	{
		box[0][0]=box[0][1]=box[0][2]=INF;//添加一地板
		number=0;
		for(i=0;i<n;++i)
		{
			scanf("%d %d %d",&a,&b,&c);
			oriente(++number,a,b,c);
			oriente(++number,b,c,a);
			oriente(++number,c,a,b);
		}
		memset(height,-1,sizeof(height));
		printf("Case %d: maximum height = %d\n",cases++,DP(0));
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值