HDU 1069—— Monkey and Banana——————【dp】
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn = 1000;
struct Cube{
int a,b,h;
}cube[maxn];
int dp[maxn];
bool cmp(Cube a,Cube b){
if(a.a == b.a)
return a.b < b.b;
return a.a < b.a;
}
int main(){
int n,cnt = 0;
while(scanf("%d",&n)!=EOF&&n){
memset(dp,0,sizeof(dp));
for(int i = 1; i <= 3*n; i+=3){
int aa,bb,cc;
scanf("%d%d%d",&aa,&bb,&cc);
for(int j = 0; j < 3; j++){
if(j == 1)
swap(aa,cc);
if(j == 2)
swap(bb,cc);
cube[i+j].a = aa;
cube[i+j].b = bb;
if(cube[i+j].a > cube[i+j].b){
swap(cube[i+j].a,cube[i+j].b);
}
cube[i+j].h = cc;
}
}
sort(cube+1,cube+1+3*n,cmp);
for(int i = 1; i <= 3*n;i ++){
dp[i] = cube[i].h;
}
for(int i = 1; i <= 3*n; i++){
for(int j = i+1; j <= 3*n; j++){
if(cube[j].a > cube[i].a && cube[j].b > cube[i].b){
dp[j] = max(dp[j],dp[i]+cube[j].h);
}
}
}
int ans = 0;
for(int i = 1; i <= 3*n;i++)
ans = max(ans,dp[i]);
printf("Case %d: maximum height = %d\n",++cnt,ans);
}
return 0;
}
HDU 1069—— Monkey and Banana——————【dp】的更多相关文章
- hdu 1069 Monkey and Banana 【动态规划】
题目 题意:研究人员要测试猴子的IQ,将香蕉挂到一定高度,给猴子一些不同大小的箱子,箱子数量不限,让猩猩通过叠长方体来够到香蕉. 现在给你N种长方体, 要求:位于上面的长方体的长和宽 要小于 下面 ...
- HDU 1069 Monkey and Banana 基础DP
题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...
- HDU 1069 Monkey and Banana(DP——最大递减子序列)
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 题意描述: 给n块砖,给出其长,宽和高 问将这n块砖,怎样叠放使得满足以下条件使得 ...
- HDU 1069 Monkey and Banana (dp)
题目链接 Problem Description A group of researchers are designing an experiment to test the IQ of a monk ...
- HDU1069 - Monkey and Banana【dp】
题目大意 给定箱子种类数量n,及对应长宽高,每个箱子数量无限,求其能叠起来的最大高度是多少(上面箱子的长宽严格小于下面箱子) 思路 首先由于每种箱子有无穷个,而不仅可以横着放,还可以竖着放,歪着放.. ...
- HDU 1069 Monkey and Banana ——(DP)
简单DP. 题意:给出若干种长方体,如果摆放时一个长方体的长和宽小于另一个的长宽,那么它可以放在另一个的上面,问最高能放多少高度.每种长方体的个数都是无限的. 做法:因为每种个数都是无限,那么每种按照 ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- 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(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
随机推荐
- .net core 结合nlog使用Elasticsearch , Logstash, Kibana
什么是ELK ELK是三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是开源软件.新增了一个FileBeat,它是一个轻量级的日志收集处理工具 ...
- C# 抽象(2)
接着上章说: 先看代码 abstract class Human { public abstract void Think(); public abstract int Age { get; set; ...
- 5w5:第五周程序填空题1
描述 写一个MyString 类,使得下面程序的输出结果是: 1. abcd-efgh-abcd- 2. abcd- 3. 4. abcd-efgh- 5. efgh- 6. c 7. abcd- 8 ...
- GitHub+Hexo 搭建个人网站详细教程
原文链接 GitHub+Hexo 搭建个人网站详细教程 前言: 随着互联网浪潮的翻腾,国内外涌现出越来越多优秀的社交网站让用户分享信息更加便捷.然后,如果你是一个不甘寂寞的程序猿(媛),是否也想要搭建 ...
- 【转】C#使用Oracle.ManagedDataAccess.dll
源地址:https://www.cnblogs.com/goldenbridge/p/7812081.html
- 获取表单提交的数据getParameter()方法
请求对象:request public String getParameter(String name); 通过request的getParameter(String name)方法获取 表单里面的n ...
- FJWC2019 子图 (三元环计数、四元环计数)
给定 n 个点和 m 条边的一张图和一个值 k ,求图中边数为 k 的联通子图个数 mod 1e9+7. \(n \le 10^5, m \le 2 \times 10^5, 1 \le k \le ...
- 洛谷 P2677 超级书架 2 题解
传送门 题目描述 Farmer John最近为奶牛们的图书馆添置了一个巨大的书架,尽管它是如此的大,但它还是几乎瞬间就被各种各样的书塞满了.现在,只有书架的顶上还留有一点空间. 所有N(1 <= ...
- 蓝牙4.0BLE抓包(二) – 广播包解析
版权声明:本文为博主原创文章,转载请注明作者和出处. 作者:强光手电[艾克姆科技-无线事业部] 在使用EN-Dongle捕获和解析广播包之前,我们先了解一下BLE报文的结构,之后,再对捕获的广播 ...
- ssh 远程登录TX2
TX2 端SSH操作 安装: sudo apt-get install openssh-server 确认sshserver是否启动: ps -e |grep ssh 如果看到sshd那说明ssh-s ...