HDU 1069 Monkey and Banana(动态规划)
Monkey and Banana
The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height.
They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.
Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.
representing the number of different blocks in the following data set. The maximum value for n is 30.
Each of the next n lines contains three integers representing the values xi, yi and zi.
Input is terminated by a value of zero (0) for n.
题目大意:给出箱子的长、宽、高,每个箱子有很多种,然后求叠起来的最大高度,上边箱子的长和宽必须小于下边的箱子
代码如下:
# include <iostream>
# include<cstdio>
# include<cstring>
# include<cstdlib>
using namespace std;
struct node
{
int x,y,z;
} s[]; int cmp(const void *a,const void *b)
{
struct node* aa = (node *)a;
struct node* bb = (node *)b;
if(aa->x != bb->x)
return aa->x - bb->x;
else if(aa->y != bb->y)
return aa->y - bb->y;
return aa->z - bb->z;
}
int dp[];
int main()
{
int n,i,j,a,b,c;
int cas = ;
while(scanf("%d",&n)&&n)
{
for(i=; i<n; i++)
{
scanf("%d%d%d",&a,&b,&c);
s[i*].x = a; s[i*].y = b; s[i*].z = c;
s[i*+].x = a; s[i*+].y = c; s[i*+].z = b;
s[i*+].x = b; s[i*+].y = a; s[i*+].z = c;
s[i*+].x = b; s[i*+].y = c; s[i*+].z = a;
s[i*+].x = c; s[i*+].y = a; s[i*+].z = b;
s[i*+].x = c; s[i*+].y = b; s[i*+].z = a;
}
qsort(s,n*,sizeof(s[]),cmp);
for(i=; i<*n; i++)
dp[i] = s[i].z;
int ans = ;
for(i=; i<n*; i++)
{
for(j=; j<i; j++)
{
if(s[i].x > s[j].x && s[i].y > s[j].y && dp[j]+s[i].z > dp[i])
dp[i] = dp[j]+s[i].z ;
}
if(dp[i]>ans)
ans = dp[i];
}
printf("Case %d: maximum height = %d\n",cas++,ans);
}
return ;
}
HDU 1069 Monkey and Banana(动态规划)的更多相关文章
- HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)
HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
- HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana(二维偏序LIS的应用)
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069—— Monkey and Banana——————【dp】
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1069 Monkey and Banana
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana(DP 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
随机推荐
- Oracle函数汇总
日期函数 1. select sysdate from dual 查询当前日期 2. select months_between() from dual 查询两个日期的月份差 3. select ad ...
- 一步一步学android控件(之十五) —— DegitalClock & AnalogClock
原本计划DigitalClock和AnalogClock单独各一篇来写,但是想想,两个控件的作用都一样,就和在一起写一篇了. DegitalClock和AnalogClock控件主要用于显示当前时间信 ...
- linux系统基础(二)
磁盘管理(一) Linux设备认识 /dev/cdrom /dev/sr0 /dev/mouse /dev/sda /dev/hda IDE硬盘(支持4块):hd(a-d) [非IDE硬盘]SCSI硬 ...
- The maximum number of cell styles was exceeded. You can define up to 4000 styles
POI操作Excel中,导出的数据不是很大时,则不会有问题,而数据很多或者比较多时, 就会报以下的错误,是由于cell styles太多create造成,故一般可以把cellstyle设置放到循环外面 ...
- centos 改动字符集为GB2312的方法
这几天总是被一个问题困扰着,那就是base64的加密,在centos server上无法解密.经过重复測试才发现,原来是由于centos 系统没有GB2312库导致的. 加密端是在ASP.NET中处理 ...
- [Practical Git] Diagnose which commit broke something with git bisect
Sometimes you find a bug in your project that has been around for a while without being noticed; it ...
- iOS开发——新特性OC篇&IOS9 系统新特性
IOS9 系统新特性 2015年6月89号凌晨召开的WWDC 2015苹果开发者大会发布了全新的iOS 9系统,PC6小编今天给大家整理了这次iOS9的系统更新带来了哪些新的功能与升级,本次新功能一览 ...
- ABAP程序执行效率和优化 ABAP Performance Examples
一. SQL Interface1. Select ... Where vs. Select + Check用Select … Where语句效率比Select ...
- Android 快速开发框架网络篇-Android-Async-Http
一.基本用法 AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.google.com", ...
- html笔记 横向两列布局
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...