hdu1069Monkey and Banana(动态规划)
Monkey and Banana
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20500    Accepted Submission(s): 10969
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.
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
题意:给出n种矩形积木,和积木的长宽高三个属性值,这个值每个值都可以表示长宽高中一种,例如1 2 3就有6种组合123 132 213 231 312 321
要求输出他们堆起来能达到的最大高度(上面积木的底座要小于下面积木的底座)
用动态规划做
因为和他们的底座面积有关,每种积木最多有3种底座面积,可以根据2条边长排序(也相当于根据底座面积排序),排成最大值,最后变成求最大子列和。
#include<bits/stdc++.h>
using namespace std;
int dp[];
struct node
{
int x,y,z; }a[];
bool cmp(node a,node b)//x升序 x相等 y升序
{
if(a.x!=b.x)
{
return a.x<b.x;
}
else
{
return a.y<=b.y;
}
} int main() {
int n;int cases=;
while(~scanf("%d",&n),n)
{
cases++;
int num=;
for(int i=;i<n;i++)
{
int x,y,z;
scanf("%d %d %d",&x,&y,&z);
// if(x==y&&y==z)
// {
// a[num].x=x;
// a[num].y=x;
// a[num].z=x;
// num++;
// }
// else
// {
a[num].x=x;
a[num].y=y;
a[num].z=z;
num++;
a[num].x=x;
a[num].y=z;
a[num].z=y;
num++;
a[num].x=y;
a[num].y=x;
a[num].z=z;
num++;
a[num].x=y;
a[num].y=z;
a[num].z=x;
num++;
a[num].x=z;
a[num].y=x;
a[num].z=y;
num++;
a[num].x=z;
a[num].y=y;
a[num].z=x;
num++;
// } }
memset(dp,,sizeof(dp));
sort(a,a+num,cmp);
int maxx=;
dp[]=a[].z;
for(int i=;i<num;i++)//每次都和前面的比 摆放要求上小下大,这边是从上往下找的,先最小的(最上面),再大的
{
int temp=;//记录前面几个里面高度最大的那个 因为每次都要最优,那么就要把他放在已有的高度最高那
for(int j=i-;j>=;j--)
{
if(a[i].x>a[j].x&&a[i].y>a[j].y&&dp[j]>temp)//因为排过序,所以大的在后,小的在前
{
temp=dp[j]; } }
dp[i]=temp+a[i].z;//i位置处的高度
maxx=max(dp[i],maxx);//所求的答案
}
printf("Case %d: maximum height = %d\n",cases,maxx);
}
return ;
}
hdu1069Monkey and Banana(动态规划)的更多相关文章
- 动态规划:HDU1069-Monkey and Banana
		
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
 - HDU——Monkey and Banana 动态规划
		
Monkey and Banana Time Limit:2000 ...
 - (动态规划 最长有序子序列)Monkey and Banana --HDU --1069
		
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1069 http://acm.hust.edu.cn/vjudge/contest/view.action ...
 - 杭电ACM分类
		
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
 - 转载:hdu 题目分类 (侵删)
		
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
 - Monkey and Banana 题解(动态规划)
		
Monkey and Banana 简单的动态规划 1.注: 本人第一篇博客,有啥不足还请多多包涵,有好的建议请指出.你以为有人读你博客,还给你提意见. 2.原题 Background: A grou ...
 - HDU 1069 Monkey and Banana(动态规划)
		
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
 - Monkey and Banana(HDU 1069 动态规划)
		
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
 - 动态规划:Monkey and Banana
		
Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. T ...
 
随机推荐
- 生成并部署SSH key
			
1.如何生成ssh公钥 你可以按如下命令来生成 sshkey: ssh-keygen -t rsa -C "xxxxx@xxxxx.com" # Generating public ...
 - javascript-数字转罗马数字
			
阿拉伯数字与罗马数字转换 罗马数字表示 XXI, 21 个位数举例I, 1 ]II, 2] III, 3] IV, 4 ]V, 5 ]VI, 6] VII, 7] VIII,8 ]IX, 9 ·十位数 ...
 - CentOS gitlab 安装配置
			
CentOS gitlab 安装配置 2018-11-02 11:23:09 Visit 5 在/etc/yum.repos.d 目录下创建文件gitlab-ce.repo,使用国内的安装源 b ...
 - 相机姿态估计(Pose Estimation)
			
(未完待续.....) 根据针孔相机模型,相机成像平面一点的像素坐标p和该点在世界坐标系下的3D坐标P有$p=KP$的关系,如果用齐次坐标表示则有: $$dp=KP$$ 其中d是空间点深度(为了将p的 ...
 - MVC学习八:MVC View提交数据
			
学习编程最主要的就是数据交互,MVC中数据交互是怎么样的呢? 1.Controller向View传输数据在http://www.cnblogs.com/WarBlog/p/7127574.html中有 ...
 - 【Node.js】新建一个NodeJS 4.X项目
			
前提工作 1.安装Node.js 各种下一步就好 2.安装NPM(node package manager) 安装好Node.js之后,打开cmd,输入npm install npm -g,程序会自动 ...
 - STM32之关闭JTAG
			
1.有些时候不想用JTAG口(而用SWJ在线调试),把JTAG暂用的IO通过remap出来使用 2.比如48 pin的STM32F103CBT6单片机: GPIO_PinRemapConfig(GPI ...
 - 课时25.a标签基本使用(掌握)
			
什么是a标签? 我们打开百度或者淘宝网页,观察任何一个超链接都会发现它有如下特质: 有下划线 移上去有小手指 可以点击 a标签的作用:就是用于控制页面与页面之间跳转的 a标签的格式:<a hre ...
 - MySQL学习【第三篇用户管理】
			
一.用户管理 1.给mysql用户设密码以及删除用户 1.给mysql的root用户设置密码 [root@db02 scripts]# mysqladmin -uroot -p password '1 ...
 - 在JSP中使用formatNumber控制要显示的小数位数
			
先引入标签库 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 比 ...