当前位置: 首页 > 编程日记 > 正文

NYOJ-232 How to eat more Banana

How to eat more Banana

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述
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.
输入
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.
输出
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".
样例输入
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
样例输出
Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
来源
Trinity
题意:
  给定n种三个边长不完全相同的长方体,每种长方体的数量无限多,长方体的每个面都可以做底,现要求将这些长方体一个一个摞起来,一个长方体可以摞在另一个长方体上边,当且仅当上边长方体的长和宽必须严格大于下边长方体的长和宽,问在满足要求的情况下最多可以摞起来的高度是多少?
题解:
  将给定的一个长宽高的长方体,将每种可能的方法分别划分为不同的长方体(即按照规定的长宽高放),然后按照长宽从大到小排序,则最后的结果就是LIS的算法了。
 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 struct node 
 9 {
10     int l;
11     int w;
12     int h;
13 }a[100];
14 int dp[100];
15 
16 int max(int m, int n)
17 {
18     return m > n ? m : n;
19 }
20 
21 int min(int m, int n)
22 {
23     return m < n ? m : n;
24 }
25 
26 bool cmp(node p, node q)
27 {
28     return (p.l > q.l || p.l == q.l && p.w > q.w);
29 }
30 
31 int main()
32 {
33     int n, cnt, x, y, z, max_h;
34     int T = 1;
35     while(scanf("%d", &n), n)
36     {
37         cnt = 0;
38         memset(dp, 0, sizeof(dp));
39         while(n--)
40         {
41             scanf("%d%d%d", &x, &y, &z);
42             
43             a[cnt].l = max(x, y);
44             a[cnt].w = min(x, y);
45             a[cnt++].h = z;
46            
47             a[cnt].l = max(x, z);
48             a[cnt].w = min(x, z);
49             a[cnt++].h = y;
50             
51             a[cnt].l = max(z, y);
52             a[cnt].w = min(z, y);
53             a[cnt++].h = x;
54         }
55         
56         sort(a, a+cnt, cmp);
57 
58         for(int k = 0; k < cnt; ++k)  // 注意别忘了这里 dp 的初始化,让我调试了半天
59             dp[k] = a[k].h;
60 
61         max_h = dp[0];
62         for(int i = 1; i < cnt; ++i)
63         {
64             for(int j = 0; j < i; ++j)
65             {
66                 if(a[j].l > a[i].l && a[j].w > a[i].w && dp[j]+a[i].h>dp[i])
67                     dp[i] = dp[j]+a[i].h;
68             }
69             if(max_h < dp[i])
70                 max_h = dp[i];
71         }
72         printf("Case %d: maximum height = %d\n", T++, max_h);
73     }
74     return 0;
75 }

转载于:https://www.cnblogs.com/dongsheng/archive/2013/05/25/3098988.html

相关文章:

UIView Animation

作者 嘿o大远 关注 2017.03.23 17:02* 字数 402 阅读 47评论 1喜欢 3今天总结一下UIView动画就是 UiView动画是基于高层API封装进行封装的,对UIView的属性进行修改时候所产生的动画. 基本动画 下面两种方法是最常用的两种. (void)animateWithDuration:(NSTimeInterval)duratio…

[转]Ext Grid控件的配置与方法

http://www.blogjava.net/wangdetian168/archive/2011/04/12/348651.html 1、Ext.grid.GridPanel 主要配置项&#xff1a; store&#xff1a;表格的数据集 columns&#xff1a;表格列模式的配置数组&#xff0c;可自动创建ColumnModel列模式 autoExpandColumn&#xff1a;自动充…

永久设置SecureCRT的背景色和文字颜色方案

对于默认的连接颜色感觉不舒服&#xff0c;一通乱搞&#xff0c;总结出这些。 一、对于临时设置&#xff0c;可以如下操作&#xff1a; 首先options -- session - appearance 此处可以设置临时的窗口背景&#xff0c;字体颜色&#xff0c;大小等等&#xff0c;为什么说是临时&a…

利用Procdump+Mimikatz获取Windows帐户密码

0x01 前言&#xff1a; 前段时间拿下一个网站的shell&#xff0c;很幸运的是直接就是System权限&#xff0c;结果发现执行添加用户命令并不能成功回显 看了下系统进程&#xff0c;原来是开启了360的主动防御&#xff0c;奈何也不会做免杀&#xff0c;上传exp运行就被杀&#x…

一个逻辑清晰的购物车模型

效果图 2017-03-25 18.28.23.gifGitHub: https://github.com/lll1024/JVShopcart 说明 这是一个具备常规功能并方便改造的购物车模型 一共包含五个模块&#xff1a; JVShopcartViewController: 购物车控制器 负责协调Model和View 只有100多行代码JVShopcartFormat: 负责网络请求…

Nginx基本配置、性能优化指南

转载自&#xff1a;http://www.chinaz.com/web/2015/0424/401323.shtml 大多数的Nginx安装指南告诉你如下基础知识——通过apt-get&#xff0c;或yum安装&#xff0c;修改这里或那里的几行配置&#xff0c;好了&#xff0c;你已经有了一个Web服务器了&#xff01;而且&#xff…

关于批量修改AD域用户的脚本

最近几天帮人弄了个脚本&#xff0c;是修改域用户属性的脚本&#xff0c;今天看到徐火军写的 关于批量修改用户属性 脚本&#xff0c;觉得有必要把我的成果分享给大家。什么都不说了&#xff0c;上脚本&#xff1a; Dim oFSO, oTF, iDim sLineDim sLoginName 用户批量文件Const…

Python multiprocess 多进程模块

转发&#xff1a;http://www.langzi.fun/Python multiprocess 多进程模块.html 需要注意的是&#xff0c;如果使用多线程&#xff0c;用法一定要加上if __name____main__:(Python中的multiprocess提供了Process类&#xff0c;实现进程相关的功能。但是它基于fork机制&#xff…

PHP正则数组

<?php //正则表达式//斜杠代表定界符 /^$///$str "好厉害18653378660了hi请勿嫁得好15165339515安徽dah矮冬瓜 拍行业大概啊好广东也欺负偶怕哈";//$reg "/(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}/";//echo preg_repl…

iOS Socket Client 通讯

iOS Socket Client 通讯 阅读 239收藏 192017-03-29原文链接&#xff1a;https://github.com/guangzhouxia/JTSocketiOS Socket Client 通讯&#xff08;偏流程和代码展示&#xff09;&#xff0c;具体原理可以在网上搜索到很多&#xff0c;就不多做追叙复制了。。。 —— 由广…

api工程IOS学习:在IOS开发中使用GoogleMaps SDK

今天一直在学习api工程之类的问题,今天正好有机会和大家分享一下. 官方文档地址&#xff1a;https://developers.google.com/maps/documentation/ios/start#getting_the_google_maps_sdk_for_ios 一、申请一个收费的API KEY 要应用GoogleMaps SDK&#xff0c;必须要为你的应用申…

Python多进程与进程锁的基本使用

Python的multiprocessing模块提供了多种进程间通信的方式&#xff0c;如Queue、Pipe等。 Queue是multiprocessing提供的一个模块&#xff0c;它的数据结构就是"FIFO——first in first out"的队列&#xff0c;常用的方法有&#xff1a;put(object)入队&#xff1b;g…

[容易]比较字符串

题目来源&#xff1a;http://www.lintcode.com/zh-cn/problem/compare-strings/ 先贴上错误代码&#xff0c;测试案例没有全部通过。不一定是顺序的。 1 class Solution {2 public:3 /**4 * param A: A string includes Upper Case letters5 * param B: A string…

iOS 一行命令发布 Pod 框架

作者 ripperhe 关注 2017.03.30 23:38* 字数 5589 阅读 27评论 0喜欢 2前言 目前比较流行的组件化开发&#xff0c;针对多个 app 要用同一套代码&#xff0c;将其做成 pod 仓库是比较好的解决方案。代码只有一份放在组件仓库&#xff0c;需要集成的 app 只需要将其 pod 到工程内…

[bbk4966]第70集 第8章 -性能维护 01

本章前言: 每秒钟&#xff0c;产生的日志文件多少&#xff0c;如果产生很多的redo log 信息&#xff0c;说明负荷量大差生的原因是DML操作太多. 假如oracle database 属于dedicate server&#xff0c;使用top session方式排查数据库性能问题&#xff0c;是比较适合的.根据SESSI…

Python中正则匹配与中文的问题

笔者改写了一个爬虫&#xff0c;来爬取补天SRC的漏洞认领页面&#xff0c;将单位名称、漏洞名称、漏洞危害等级爬取下来&#xff0c;但是在正则匹配"漏洞名称"的过程中遇到了一些麻烦。 如上图&#xff0c;想要把"SQL注入漏洞"字符串正则匹配出来&#xf…

项目/程序的流程走向

领导用户需求前景准备分析(OOA)设计(OOD)实现(OOP)测试部署发布跟踪维护升级新田月会|新细胞|君宁天下|htttp://www.xintianyuehui.cn 作者&#xff1a;宁骑 联系QQ&#xff1a;1075858260转载于:https://www.cnblogs.com/ncellit/p/5491828.html

使用 UIBezierPath 进行简单的图形绘制

这篇文章介绍UIBezierPath的详细的使用, 以及一些细节! 创建一个XTBezierPath继承于UIView的类 使用drawRect 完成图形的绘制 在drawRect方法完成绘制 使用 moveToPoint, addLineToPoint两个方法绘制一个任意多边形 其中w, h 代表自定义View的宽, 高 代码如下: // 初始化一个UI…

利用python实现IP扫描

需求&#xff1a;写一个脚本&#xff0c;判断192.168.11.0/24网络里&#xff0c;当前在线ip有哪些&#xff1f; 知识点: 1 使用subprocess模块&#xff0c;来调用系统命令&#xff0c;执行ping 192.168.11.xxx 命令 2 调用系统命令执行ping命令的时候&#xff0c;会有返回值…

EFQRCode:自动生成花式二维码

原文链接&#xff1a;https://github.com/EyreFree/EFQRCodeEFQRCode&#xff1a;自动生成花式二维码。# 为开源点赞# —— 由SwiftLanguage分享EFQRCode is a tool to generate QRCode UIImage or recognize QRCode from UIImage, in Swift. It is based on CIDetector and CI…

centos删除系统自带的httpd

centos删除系统自带的httpd 1、[rootlocalhost etc]# rpm -qa|grep httpd&#xff0c;查看与httpd相关软件包。 httpd-tools-2.2.15-15.el6.centos.i686 httpd-2.2.15-15.el6.centos.i686 www.2cto.com 2、然后删除httpd&#xff1a; [rootlocalhost etc]# rpm -e httpd 出现问…

[C#]ASP.NET MVC 3 在线学习资料

最近在研究如何把Twitter Bootstrap移植到ASP.NET MVC 3上&#xff0c;攒了点资料&#xff0c;先贴在之里&#xff0c;以后整理了写心得。 1. http://www.codeproject.com/Articles/404633/Transform-ASP-NET-MVC3-Default-Template-with-Twitt 这是一篇介绍如何把默认的ASP.NE…

域渗透提权之MS14-068

0x00 前言 在做渗透测试时&#xff0c;当遇到域环境&#xff0c;获取到一个域成员账号后&#xff0c;如果域控制器未打好补丁&#xff0c;则可以利用本文所提到的漏洞&#xff0c;快速获取到域控制器权限。笔者这里总结网上已有资料&#xff0c;加以描述&#xff0c;希望你能在…

iOS 高可控性日历基础组件 - SKCalendarView 的使用和实现思路的分享

阅读 61收藏 52017-04-02原文链接&#xff1a;http://www.jianshu.com/p/ce4c64a4d437SKCalendarView 是一个高可控性的日历基础组件&#xff0c;为了提高应用的自由度&#xff0c;默认只提供了日历部分的视图封装&#xff0c;但不涵盖切换月份按钮、年月分显示等非关键性控件&…

懒加载 字典转模型 自定义cell

1 懒加载: 1> 什么是懒加载? 懒加载又称为延时加载,即在系统调用的时候加载,如果系统不调用则不会加载.所谓的懒加载其实就是重写其 get 方法. 2> 特点:在使用懒加载的时候要先判断该方法是否已经存在,如果不存在则再进行实例化. 3> 优点: 不必将创建对象的方法都…

SQL GROUP BY 语句

合计函数 (比如 SUM) 常常需要添加 GROUP BY 语句。 GROUP BY 语句 GROUP BY 语句用于结合合计函数&#xff0c;根据一个或多个列对结果集进行分组。 SQL GROUP BY 语法 SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator valu…

docker如何push镜像到docker hub个人的仓库

docker如何push镜像到docker hub个人的仓库 step1——找到本地镜像的ID&#xff1a;docker imagesstep2——登陆Hub&#xff1a;docker login --usernameusername --passwordpassword --emailemailstep3——tag&#xff1a;docker tag <imageID> <namespace>/<…

博客开通第一天,加油

博客开通第一天&#xff0c;加油转载于:https://www.cnblogs.com/tianyang01/p/5499881.html

【iOS 开发】iOS 10.3 如何更换 app 图标

2017-04-06 KyrieXu Cocoa开发者社区iOS 10.3 开放了更换 app 图标的 API&#xff0c;核心方法是下面这个&#xff1a; func setAlternateIconName(_ alternateIconName: String?, completionHandler: ((Error?) -> Void)? nil) 这是官方文档&#xff0c;但是你还需要在…