NYOJ 232 How to eat more Banana
How to eat more Banana
- 描述
- 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
- 上传者
- 张洁烽
-
解题:每一种类型最多可以有三种放置方法。排序后求最长上升子序列就可以了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
struct tower {
int l,w,h;
} p[];
bool cmp(const tower &x,const tower &y){
return (x.l < y.l || x.l == y.l&& x.w < y.w);
}
int main() {
int cnt,n,i,j,x,y,z,ans;
int dp[],k = ;
while(scanf("%d",&n),n) {
cnt = ;
for(i = ; i < n; i++) {
scanf("%d%d%d",&x,&y,&z);
p[cnt].l = max(x,y);
p[cnt].w = min(x,y);
p[cnt++].h = z;
p[cnt].l = max(x,z);
p[cnt].w = min(x,z);
p[cnt++].h = y;
p[cnt].l = max(y,z);
p[cnt].w = min(y,z);
p[cnt++].h = x;
}
sort(p,p+cnt,cmp);
for(i = ; i < cnt; i++)
dp[i] = p[i].h;
ans = INT_MIN;
for(i = ; i < cnt; i++){
for(j = i-; j >= ; j--){
if(p[j].l < p[i].l && p[j].w < p[i].w && dp[i] < dp[j]+p[i].h)
dp[i] = dp[j]+p[i].h;
}
if(dp[i] > ans) ans = dp[i];
}
printf("Case %d: maximum height = %d\n",k++,ans);
}
return ;
}
NYOJ 232 How to eat more Banana的更多相关文章
- 多邻国学英语 tips
来源: https://www.cnblogs.com/daysme整理了一分多邻国学英语中的相关语法文档. 地方 null 现在完成时 null 反身代词 浓缩的精华:反身代词就是 “XX 自己” ...
- Python - 使用pycallgraph生成函数关系图
1- pycallgraph简介 可用于创建python函数关系图,依赖于dot命令,需要先安装 graphviz: HomePage:http://pycallgraph.slowchop.com/ ...
- Python之路【第十一篇】: 进程与线程
阅读目录 一. cpython并发编程之多进程1.1 multiprocessing模块介绍1.2 Process类的介绍1.3 Process类的使用1.4 进程间通信(IPC)方式一:队列1.5 ...
- 详解javascript实现自定义事件
这篇文章主要为大家介绍了javascript实现自定义事件的方法,自定义事件,顾名思义,就是自己定义事件类型,自己定义事件处理函数,javascript如何实现自定义事件,需要了解的朋友可以参考下 我 ...
- python函数调用关系图(python call graph)
由于要重构项目的部分代码,要整理好主要的函数调用关系,不想自己看代码慢慢画出结构,想找出一种通用的,节省人力的方法得出函数间的调用关系图,于是发现以下几个工具.(内网没装好graphviz,还没真正用 ...
- js 自定义事件 包含 添加、激活、销毁
1.思路 (1)构思 var eventTarget = { addEvent: function(){ //添加事件 }, fireEvent: function(){ //触发事件 }, remo ...
- java 多态 总结
1.前言 引用教科书解释: 多态是同一个行为具有多个不同表现形式或形态的能力. 多态就是同一个接口,使用不同的实例而执行不同操作. 通俗来说: 总结:多态的抽象类与接口有点相似: 父类不需要具体实现方 ...
- (LightOJ 1004) Monkey Banana Problem 简单dp
You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...
- F - Monkey Banana Problem
F - Monkey Banana Problem Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & ...
随机推荐
- zTree树插件动态加载
需求: 由于项目中家谱图数据量超大,而一般加载方式是通过,页面加载时 zTree.init方法进行数据加载,将所有数据一次性加载到页面中.而在项目中家谱级别又非常广而深,成千上万级,因此一次加载,完全 ...
- aspectj xml
1.接口和类 1.1 ISomeService 接口 public interface ISomeService { public void doSome(); public void dade(); ...
- java 利用c3p0管理数据库连接池
数据库连接池类,用于获取数据库连接.利用单例模式保证所有的连接都只通过一个连接池管理. package com.mousewheel.dbcon; import java.io.InputStream ...
- 剑指tomcat之多项目部署问题
部署项目时遇到的问题,tomcat的webapps文件夹中有两个war包,但每次启动Tomcat服务时,只会默认启动一个war包. 解决方案一:在Tomcat主页中进入应用管理页面,手动开启项目.(进 ...
- Android 如何利用Activity的Dialog风格完成弹出框设计
在我们使用Dialog时,如果需要用到很多自己设计的控件,虽然可以让弹出框显示出我们需要的界面,但却无法找到地方完成控制代码的编写,如何解决这个问题呢,我们可以将Activity伪装成Dialog弹出 ...
- zookeeper系列 (第一章 :ubuntu 下安装zookeeper)
1.zookeeper是分布式一致性管理服务.解决了分布式中死锁,不一致,原子性操作等问题. 2.环境:系统ubuntu,zookeeper 下载地址:http://archive.apache.or ...
- 快速排序的一种Java实现
快速排序是笔试和面试中很常见的一个考点.快速排序是冒泡排序的升级版,时间复杂度比冒泡排序要小得多.除此之外,快速排序是不稳定的,冒泡排序是稳定的. 1.原理 (1)在数据集之中,选择一个元素作为&qu ...
- 初习mysql procedure
1.存储过程简介 我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,用户 ...
- How to install Eclipse?
http://askubuntu.com/questions/26632/how-to-install-eclipse How to install Eclipse? up vote113down v ...
- (八)maven学习之继承
继承 如果项目划分了多个模块,都需要依赖相似的jar包,只需要创建一个父模块,在它的pom.xml文件中配置依赖的jar包.功能模块只需要继承父模块,就可以自动得到其依赖的jar包,而不需要再每个模块 ...