动态规划:Monkey and Banana
Problem Description
A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.
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
The input file will contain one or more test cases. The first line of each test case contains an integer n,
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
For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Case case: maximum height = height".
Sample Input
1
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
Sample Output
Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
#include<stdio.h>
#include<string.h>
#include<stdlib.h> struct stu
{
int x,y,z,h;
}s[]; int cmp1(const void *a,const void *b)
{
return *(int *)b-*(int *)a;
} int cmp2(const void *a,const void *b)
{
struct stu *c,*d;
c=(struct stu*)a;
d=(struct stu*)b;
return d->x*d->y-c->x*c->y;
} int main()
{
int n,a[],i,m,maxn,j,q=;
while(scanf("%d",&n),n)
{
memset(s,,sizeof(s));
i=;
while(n--)
{
scanf("%d%d%d",&a[],&a[],&a[]);
qsort(a,,sizeof(a[]),cmp1);
s[i].x=a[];
s[i].y=a[];
s[i++].z=a[];
s[i].x=a[];
s[i].y=a[];
s[i++].z=a[];
s[i].x=a[];
s[i].y=a[];
s[i++].z=a[];
}
m=i;
qsort(s,m,sizeof(s[]),cmp2);
s[].h=s[].z;
for(i=;i<m;i++)
{
maxn=;
for(j=;j<i;j++)
{
if(s[j].h>maxn&&s[j].x>s[i].x&&s[j].y>s[i].y)
maxn=s[j].h;
}
s[i].h=s[i].z+maxn;
}
maxn=;
for(i=;i<m;i++)
{
if(s[i].h>maxn)
maxn=s[i].h;
}
printf("Case %d: maximum height = %d\n",q++,maxn);
}
return ;
}
因为有很多个积木 所以要存三次。
动态规划:Monkey and Banana的更多相关文章
- HDU——Monkey and Banana 动态规划
Monkey and Banana Time Limit:2000 ...
- 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 ...
- HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- ZOJ 1093 Monkey and Banana (LIS)解题报告
ZOJ 1093 Monkey and Banana (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- 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
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 杭电oj 1069 Monkey and Banana 最长递增子序列
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- LR 两种录制:html与url
一直在使用LR,对于Html_based script和Url-based script 两种录制方式之间,要如何选择,仍是一知半解.最近测试时遇到同样的业务功能,两种录制方式的脚本,单次执行时间差别 ...
- TensorFlow低阶API(三)—— 变量
简介 TensorFlow变量是表示程序处理的共享持久状态的最佳方法. 我们使用tf.Variable类操作变量.tf.Variable表示可通过其运行操作来改变其值的张量.与tf.Tensor对象不 ...
- EXPLAIN - 显示语句执行规划
SYNOPSIS EXPLAIN [ ANALYZE ] [ VERBOSE ] statement DESCRIPTION 描述 这条命令显示PostgreSQL规划器为所提供的语句生成的执行规划. ...
- ios 之sqllite
iOS sqlite数据库操作.步骤是: 先加入sqlite开发库libsqlite3.dylib, 新建或打开数据库, 创建数据表, 插入数据, 查询数据并打印 1.新建项目sqliteDemo,添 ...
- 模拟--P1540 机器翻译
题目连接 题目背景 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 题目描述 这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义来替换.对于每个英文单词 ...
- STL 源码分析六大组件-allocator
1. allocator 基本介绍 分配器(allocator))是C ++标准库的一个组件, 主要用来处理所有给定容器(vector,list,map等)内存的分配和释放.C ++标准库提供了默认使 ...
- 文件默认权限umask掩码
umask命令 作用:用于显示.设置文件的缺省权限 格式:umask [-S] -S表示以rwx形式显示新建文件缺省权限 系统的默认掩码是0022 文件创建时的默认权限 = 0666 - umas ...
- Mysql when case 批量更新
UPDATE categories SET display_order = CASE id WHEN 1 THEN 3 WHEN 2 THEN 4 WHEN 3 THEN 5 END WHERE id ...
- linux常用过滤日志命令
#过滤nginx访问日志awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr -k1 | head -n 10 ...
- django的基本操作流程
pip install django cd Desktop/课上代码02/ #进入到创建项目的目录 django-admin startproject 项目的名称 #创建项目 __ini ...