动态规划: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 ...
随机推荐
- Qt获取本机IP地址
Qt获取本机IP地址: Qt版本:4.8.6 #include <QtNetwork/QNetworkInterface.h> QString ipAddr; QList<QHost ...
- 推荐一款功能强大的Tomcat 管理监控工具,可替代Tomcat Manager
我们在本地启动Tomcat服务器后,用localhost:访问: 再点Manager App,即可进入Tomcat自带的Manager这个应用,此处可以单独部署/卸载每一个应用.可以看到在Manage ...
- Zotero文献管理神器使用
为什么使用Zotero管理论文? 1.可以从网上剪藏 2.可以查询 3.有作者 标题 期刊 索引 4.word自动生成论文索引 把pdf文件导入Zotero 按住ctrl+shift拖动pdf文件,就 ...
- SQLite – LIMIT子句
SQLite - LIMIT子句 SQLite LIMIT子句是用来限制SELECT语句返回的数据量. 语法: SELECT语句.LIMIT子句的基本语法如下: SELECT column1, col ...
- python之bool (布尔值)
用途: 判断真假 识记: 空的字符串是False,非空的就是True 0 是False,非0的都是True 格式: True False 布尔值转换成字符串: print(type(str(Tru ...
- js实现音量拖拽的效果模拟
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>js ...
- 【2018 CCPC网络赛】1004 - 费马大定理&数学
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6441 Knowledge Point: 1. 费马大定理:当整数n >2时,关于x, y, z的 ...
- 洛谷 P1708 天然气井 题解
https://www.luogu.org/problemnew/show/P1708 这道题还是比较好的. 读完题目我们先想想如何计算某个天然气井($x_1,y_1$)和中转站($a_1,b_1$) ...
- 配置c3p0-config.xml数据库连接池,jdbcurl配置项报错Type The reference to entity "useUnicode" must end with the ';' delimiter.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xml> <c3p0-confi ...
- Python自动化测试框架——生成测试报告
如何才能让用例自动运行完之后,生成一张直观可看易懂的测试报告呢? 小编使用的是unittest的一个扩展HTMLTestRunner 环境准备 使用之前,我们需要下载HTMLTestRunner.py ...