HDU 1069---背包---Monkey and Banana
Description
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.
Input
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.
Output
Sample Input
Sample Output
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int dp[];
struct node
{
int a,b,c;
}d[]; bool cmp(const node x,const node y)
{
if(x.a==y.a)
return x.b>y.b;
return x.a>y.a;
}
int main()
{
int n,Case=;
while(scanf("%d",&n)&&n)
{
int a,b,c;
for(int i=;i<n;i++)
{
scanf("%d%d%d",&a,&b,&c);
if(a>b) swap(a,b);
if(a>c) swap(a,c);
if(b>c) swap(b,c);
d[*i].a=a;
d[*i].b=b;
d[*i].c=c;
d[*i+].a=a;
d[*i+].b=c;
d[*i+].c=b;
d[*i+].a=b;
d[*i+].b=c;
d[*i+].c=a;
}
sort(d,d+*n,cmp);
int res=;
memset(dp,,sizeof(dp));
for(int i=;i<*n;i++)
dp[i]=d[i].c;///防止d[0~i-1]没有一个长宽均大于d[i],这时给它自己本身高度;
for(int i=;i<*n;i++)
{
for(int j=;j<i;j++)
{
if(d[j].a>d[i].a&&d[j].a&&d[j].b>d[i].b)
dp[i]=max(dp[i],dp[j]+d[i].c);
}
res=max(res,dp[i]);
}
printf("Case %d: maximum height = %d\n",Case++,res);
}
return ;
}
HDU 1069---背包---Monkey and Banana的更多相关文章
- HDU 1069:Monkey and Banana(DP)
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 Statement 一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子 ...
- hdu 1069 (DP) Monkey and Banana
题目:这里 题意: Description 一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子足够聪明,它应当能够通过合理的放置一些砖块 ...
- 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 / ZOJ 1093 Monkey and Banana (最长路径)
HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...
- (最大上升子序列)Monkey and Banana -- hdu -- 1069
http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit:1000MS Memory L ...
- 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:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- ArcGIS与SuperMap的使用比较(1)
用了超过6年的超图产品了,因此对超图的很多特性比较熟悉,去年开始接触ARCGIS,并用来研发了一些新产品,因此对于两个GIS平台有些感受,记录如下: 比较版本:ARCGIS10.1与SuperMap ...
- 学习之路三十六:SQL知识总结 - [游标||字符串分割]
好久没有写文章了,今天把前不久项目用到的SQL知识总结一下. 一丶字符串分割 SQL内置函数中是没有Split分割函数的,所以需要自己去实现,不多说,上代码: )) RETURNS @result T ...
- 纯CSS3实现3D特效的iPhone 6动画
iPhone 6发布不久,屌丝怎能买得起,不过作为程序员,今天看到一个用纯CSS3绘制的iPhone 6,由于CSS3特性的运用,带有点3D的动画特效,大家可以先来看看在线演示效果. 在线演示 ...
- CSS - toggle collapse 类似bootstrap的展开效果
问题:toggle collapse 类似bootstrap的展开效果(展开一个关闭另一个) Demo:http://jsfiddle.net/JSDavi/L47vscw4/ 方案:使用transi ...
- ACE代码编辑器,代码提示,添加自定义数据
//设置自动提示代码 var setCompleteData = function(data) { var langTools = ace.require("ace/ext/language ...
- java之对象转型2
public class TestCasting2{ public static void main(String args[]){ TestCasting2 test2= new TestCasti ...
- 如何修改Windows Azure Web App的时区
Windows Azure的时区默认使用UTC,如果是VM可以直接修改,但Azure Web Apps的隔离性导致我们无法进行设置.应用系统使用DateTime.Now的地方很多,不可能做出一一修改. ...
- [CS231n-CNN] Linear classification II, Higher-level representations, image features, Optimization, stochastic gradient descent
课程主页:http://cs231n.stanford.edu/ loss function: -Multiclass SVM loss: 表示实际应该属于的类别的score.因此,可以发现,如果实际 ...
- Three.js源码阅读笔记-5
Core::Ray 该类用来表示空间中的“射线”,主要用来进行碰撞检测. THREE.Ray = function ( origin, direction ) { this.origin = ( or ...
- java攻城狮之路(Android篇)--BroadcastReceiver&Service
四大组件:activity 显示. contentProvider 对外暴露自己的数据给其他的应用程序.BroadcastReceiver 广播接收者,必须指定要接收的广播类型.必须明确的指定acti ...