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 & ...
随机推荐
- Asp.Net实现记录历史访问人数和当前在线人数
************************************在Global.asax中如下************************ <%@ Import Namespace= ...
- 用redis实现简单的队列
在工作中,时常会有用到队列的场景,比较常见的用rabbitMQ这些专业的组件,官网地址是:http://www.rabbitmq.com,重要的是官方有.net的客户端,但是如果对rabbitMQ不熟 ...
- 第八章 设计用户界面 之 给Web程序应用用户界面设计
1. 概述 本章内容包括: 使用CSS创建和应用样式.使用HTML构架用户界面的层次 以及 根据需求实现动态页面内容. 2. 主要内容 2.1 使用CSS创建和应用样式 Razor程序的模板是_Lay ...
- 初识react中的状态量
react组件中的两类状态数据:props,state,官网API给出的使用规范,多读几遍,受益匪浅: 结论: 1. 对应任何可变的数据,理应只有一个单一“ 数据源 ” 2. 如果多个组件均需要这些数 ...
- UVA 11584 Partitioning by Palindromes 划分回文串 (Manacher算法)
d[i]表示前面i个字符划分成的最小回文串个数, 转移:当第i字符加进来和前面区间j构成回文串,那么d[i] = d[j]+1. 要判断前面的字符j+1到i是不是回文串,可以用Manacher算法预处 ...
- [BZOJ3307]:雨天的尾巴(LCA+树上差分+权值线段树)
题目传送门 题目描述: N个点,形成一个树状结构.有M次发放,每次选择两个点x,y对于x到y的路径上(含x,y)每个点发一袋Z类型的物品.完成所有发放后,每个点存放最多的是哪种物品. 输入格式: 第一 ...
- Struts2 执行流程
struts2执行原理(执行流程) 一个请求在Struts2框架中的处理大概分为以下几个步骤: 1 客户端发送请求:(HttpServletRequest)2 这个请求经过一系列的过滤器(Filter ...
- shell脚本,awk如何处理文件中上下关联的两行。
文件d.txt如下内容 ggg 1portals: 192.168.5.41:3260werew 2portals: 192.168.5.43:3260 如何把文件d.txt内容变为如下内容 ggg ...
- shell脚本,如何监控目录下的文件内容是否被修改。
第一种方法是通过cmp来进行比对[root@localhost bo]# ls .html .html .html .html .html .html .html .html .html cat.sh ...
- shell脚本,配置文件加载顺序,以及什么时候加载。
在linux系统中,有/etc/profile,/etc/bashrc ,~/.bash_profile,~/bashrc这四个配置文件,这些文件,会自动的在某些时候加载,也就是点一下,一般都是些别名 ...