ZOJ 1093 Monkey and Banana(动态规划)

Monkey and Banana

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 Specification

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 xiyi and zi.
Input is terminated by a value of zero (0) for n.

Output Specification

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


动态规划的实质是记忆化搜索,也可以写成递推的形式

View Code
 1 # include<stdio.h>
 2 # define MAX 9999999
 3 
 4 int box[100][3];
 5 int height[100];
 6 int number;
 7 
 8 void baifang(int x,int a,int b,int c){
 9     box[x][0] = a;
10     box[x][1] = b;
11     box[x][2] = c;
12 }
13 
14 int DP(int x){
15     if(x>=number) 
16         return 0;
17     if(height[x] != -1)
18         return height[x];
19     int t=0;
20     int i;
21     for(i=1;i<number;i++){
22         if(box[x][0] > box[i][0] && box[x][1] > box[i][1] ||
23             box[x][1] > box[i][0] && box[x][0] >box[i][1])
24             t = DP(i) + box[i][2];
25         if(t>height[x])
26             height[x] = t;
27     }
28     return height[x];
29 }
30 
31 int main(){
32     int n;
33     int cases =1;
34     int a,b,c;
35     while(scanf("%d",&n) && n){
36         box[0][0] = box[0][1] = box[0][2] =MAX;
37         number = 1;
38         int i;
39         for(i=0;i<n;i++){
40             scanf("%d%d%d",&a,&b,&c);
41             baifang(number++,a,b,c);
42             baifang(number++,a,c,b);
43             baifang(number++,b,c,a);
44         }
45         for(i=0;i<number;i++)
46             height[i] = -1;
47         printf("Case %d: maximum height = %d\n",cases++,DP(0));
48     }
49     return 0;
50 }
View Code
 1 # include<stdio.h>
 2 # include<stdlib.h>
 3 
 4 int max(int a,int b)
 5 {
 6     return a>b?a:b;
 7 }
 8 
 9 struct block
10 {
11     int x,y,z;
12 } b[1200];
13 int h[1200];
14 int cmp(const void *a,const void *b)
15 {
16     return ((block *)b)->x - ((block *)a)->x;
17 }
18 
19 int main()
20 {
21     int n;
22     int i,j;
23     int cases =1;
24     int x,y,z,height;
25     while(scanf("%d",&n) && n)
26     {
27         for(i=0; i<n; i++)
28         {
29             scanf("%d%d%d",&x,&y,&z);
30             b[6*i].x   = x;
31             b[6*i].y   = y;
32             b[6*i].z   = z;
33             b[6*i+1].x = x;
34             b[6*i+1].y = z;
35             b[6*i+1].z = y;
36             b[6*i+2].x = y;
37             b[6*i+2].y = x;
38             b[6*i+2].z = z;
39             b[6*i+3].x = y;
40             b[6*i+3].y = z;
41             b[6*i+3].z = x;
42             b[6*i+4].x = z;
43             b[6*i+4].y = x;
44             b[6*i+4].z = y;
45             b[6*i+5].x = z;
46             b[6*i+5].y = y;
47             b[6*i+5].z = x;
48         }
49         qsort(b,6*n,sizeof(b[0]),cmp);
50         h[0] = b[0].z;
51         for (i=1; i<6*n; i++)
52         {
53             height = 0;
54             for (j=0; j<i; j++)
55                 if (b[j].x>b[i].x && b[j].y>b[i].y && h[j]>height)
56                     height = h[j];
57             h[i] = height+b[i].z;
58         }
59 
60         height = h[0];
61         for (i=1; i<6*n; i++)
62             height = max(height,h[i]);
63         printf("Case %d: maximum height = %d\n",cases++,height);
64     }
65     return 0;
66 }

 

 
C盘又红了?别慌!用傲梅分区助手绿色版(V6.3)无损扩容,保姆级图文教程 本文详细介绍了如何使用傲梅分区助手绿色版(V6.3)无损扩容C盘,解决空间不足问题。通过三步操作,用户可安全转移闲置空间至C盘,无需安装软件或担心数据丢失。文章还提供了避坑指南和系统调优建议,帮助用户彻底告别C盘焦虑。 阅读详情

相关推荐

告别C盘空间不足:傲梅分区助手绿色版 vs DiskGenius,哪款更适合你?

本文针对Windows用户常见的C盘空间不足问题,对比了傲梅分区助手绿色版DiskGenius两款主流分区工具。文章详细分析了两者在扩展C盘、操作界面、功能深度及适用场景上的差异,帮助用户根据自身技术水平选择最合适的工具,安全高效地解决磁盘空间管理难题。

brown的博客 383

分区助手_绿色版

支持把正版系统从机械硬盘移至固态硬盘,从固态硬盘备份到机械硬盘!

C盘扩容【傲梅分区助手】及BitLocker加密解除

傲梅分区助手网址:(例如:D盘)“C盘”“高级操作”“合并分区”

2301_76682353的博客 4355

如何扩容C盘?6种扩展C盘方法!

如何在Windows中扩大C盘?借助傲梅分区助手,你可以轻松实现磁盘管理无法实现的扩容功能,就算C盘后没有未分配空间时,也能通过移动空间位置,挪出未分配空间,从而实现增大C盘。该软件除了分区调整功能外,它还拥有磁盘克隆、 MBR转GPT 、应用迁移等功能,快来下载体验吧!

让每一行代码都有改变世界的力量 3万+

分区助手绿色版:磁盘管理系统迁移的高效工具

本文还有配套的精品资源,点击获取 简介:分区助手是一款强大的磁盘管理工具,具备多种实用功能,如系统迁移、备份恢复、分区管理、调整分区大小、合并拆分分区、快速克隆等。绿色版无需安装,易于使用且兼容多种Windows操作系统。此软件支持在不丢失数据的情况下进行磁盘分区操作,提高电脑性能,确保数据安全。 1. 分区助手_绿色版的系统迁移功能 在当今的数字时代,...

weixin_42518874的博客 833

zoj1093 Monkey and Banana 动态规划

Monkey and Banana Time Limit: 2 Seconds      Memory Limit: 65536 KB 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 buil

老李2009 361

Monkey and Banana (zoj 1093 动态规划)

题意:有n种长方体,数量不限,把它们堆起来,下面的底要严格大于上面的,问最高能堆多高。 思路:每种长方体可以预处理成三种长方体,然后按照底面从大到小排个序,然后的操作感觉就有点想LIS了,dp[i]表示到第i个长方体的最高高度。

@you! 569

动态规划 zoj1093 Monkey and Banana

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 bl...

weixin_30905133的博客 102

ZOJ1093 Monkey and Banana 【DP】

一、题目 ZOJ 1093 二、题目源程序 #include <stdio.h>//一个箱子有3种h..所以总共有3*n种高度.按面积从大到小排序 #include <stdlib.h> struct block { int x,y,z,h; }a[200]; int cmp(const void *a,const void *b)//快排,模版 ...

weixin_30640769的博客 198

ZOJ - 1093 Monkey and Banana 【DP】

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 block...

一定要站在自己热爱的生活里闪闪发光 3万+

ZOJ 1093 Monkey and Banana

这是一个动态规划题目,不是太难,只要理解动态规划思想就可以做出来。。。 #include #include struct node{     int x;     int y;     int z;     int s;     }S[100]; int high[100]; int cmp(const void *a,const void *b) {

恋&空的专栏 633

ZOJ 1093 Monkey and banana

#include #include #define MAXN 30#define MAX(a, b) a>b?a:b#define MIN(a, b) a>b?b:ausing namespace std;struct Block{ int w, l, h;}blks[3*MAXN];int n;

yllfever的专栏 838

zoj 1093 Monkey and Banana

#include #include #include #include #include using namespace std; typedef struct { int x; int y; int h; }edge; edge bloc

我的学习记录 594

分区助手免费工具:无损调整分区大小,轻松扩展C盘引导分区

分区助手是一款专为磁盘管理设计的高效工具,支持无损调整分区大小、合并/拆分分区、扩展系统盘、迁移操作系统至新硬盘等操作。其核心技术在于无需格式化即可重新规划磁盘空间,避免数据丢失风险。例如,在C盘空间不足时,可通过收缩相邻D盘释放未分配空间,并将其无缝合并至C盘,全过程不影响原有文件。

weixin_42511373的博客 3267

使用傲梅分区助手绿色版给C盘扩容

使用傲梅分区助手绿色版给C盘扩容 1、准备傲梅分区助手V6.3绿色专业版 2、运行分区助手 3、向导->扩展分区向导 4、选择扩展系统分区,下一步 5、点击下一步, 6、选择要分割的磁盘D,缩小D盘腾出空间给C盘,下一步 7、向右拖动滑块,或者在输入框输入大小, 8、点击下一步, 9、点击执行, 10、选择是, 11、点击确定, 12、单击完成, 13、点击取消,回到分区助手页面, 14、这时候可以看到分区成功,关闭分区.

wbd_1233的专栏 5578

一个可以扩容C盘的第三方免费软件

还在为公司发的*笔记本而发愁吗? 这里为你提供一种LJ电脑的将就使用方式,就是自己给C盘扩容。 不然你的公司本C盘可能用不了几天就要满了,而且还不知道里面放的什么(公司初始化总会给你塞些东西),还不敢删。 此时把闲置的D盘分些空间到C盘来提高运行速度就是必要的了。 话不多说来介绍下: 首先是下载链接:https://www2.aomeisoftware.com/download/pacn/PAInstall.zip 1、打开运行分区助手,找到C盘相邻的分区,比如本例中的D分区,并右键选择“调整/移动分区“。

自救 唯有自强 1万+

傲梅分区助手:调整、拆分、克隆全功能 绿色版一键搞定磁盘分区

采用绿色版发布,直接双击图标即可启动,无需安装。它支持创建、删除、扩展、收缩、合并、拆分等常见分区操作,界面简洁、使用方便,适合需要快速调整磁盘布局的用户。傲梅分区助手(绿色版)功能:调/移分区 | 拆分 | 克隆 | 创建(FAT/NTFS/exFAT) | 擦除(普通/高级) | 程序/文件夹迁移 | 合并 | 恢复 | 磁盘信息查看 | 批量操作,双击图标即可打开,无需安装。傲梅分区助手是一款经典的磁盘分区管理工具,

2501_92644093的博客 330
上一篇: 树的基本概念
下一篇: Monkey
weixin_33762321
博客等级 码龄11年 5228粉丝 176原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值