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
上传者
张洁烽
解题:每一种类型最多可以有三种放置方法。排序后求最长上升子序列就可以了。
 #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的更多相关文章

  1. 多邻国学英语 tips

    来源: https://www.cnblogs.com/daysme整理了一分多邻国学英语中的相关语法文档. 地方 null 现在完成时 null 反身代词 浓缩的精华:反身代词就是 “XX 自己” ...

  2. Python - 使用pycallgraph生成函数关系图

    1- pycallgraph简介 可用于创建python函数关系图,依赖于dot命令,需要先安装 graphviz: HomePage:http://pycallgraph.slowchop.com/ ...

  3. Python之路【第十一篇】: 进程与线程

    阅读目录 一. cpython并发编程之多进程1.1 multiprocessing模块介绍1.2 Process类的介绍1.3 Process类的使用1.4 进程间通信(IPC)方式一:队列1.5 ...

  4. 详解javascript实现自定义事件

    这篇文章主要为大家介绍了javascript实现自定义事件的方法,自定义事件,顾名思义,就是自己定义事件类型,自己定义事件处理函数,javascript如何实现自定义事件,需要了解的朋友可以参考下 我 ...

  5. python函数调用关系图(python call graph)

    由于要重构项目的部分代码,要整理好主要的函数调用关系,不想自己看代码慢慢画出结构,想找出一种通用的,节省人力的方法得出函数间的调用关系图,于是发现以下几个工具.(内网没装好graphviz,还没真正用 ...

  6. js 自定义事件 包含 添加、激活、销毁

    1.思路 (1)构思 var eventTarget = { addEvent: function(){ //添加事件 }, fireEvent: function(){ //触发事件 }, remo ...

  7. java 多态 总结

    1.前言 引用教科书解释: 多态是同一个行为具有多个不同表现形式或形态的能力. 多态就是同一个接口,使用不同的实例而执行不同操作. 通俗来说: 总结:多态的抽象类与接口有点相似: 父类不需要具体实现方 ...

  8. (LightOJ 1004) Monkey Banana Problem 简单dp

    You are in the world of mathematics to solve the great "Monkey Banana Problem". It states ...

  9. F - Monkey Banana Problem

    F - Monkey Banana Problem Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & ...

随机推荐

  1. P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers

    题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人.然而,在任何一群朋友中 ...

  2. linux下mysql中文乱码

    登录mysql执行mysql> show variables like 'character%';发现编码有些不是utf-8 修改/etc/mysql/my.cnf,网上说的是/etc/my.c ...

  3. 1、二维数组中的查找------------>剑指offer系列

    题目 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. ...

  4. Linux下环境搭建(一)——java、tomcat配置

    通过2个周末小憩的时间,终究是把linux环境下的jenkins+gitlab+jmeter框架给弄好了.jenkins的配置系列文章,可以翻看我以前的博文.此次,就将在linux下搭建环境的过程以博 ...

  5. iOS NSDate 常用日期相关函数的封装

    Category是类别,一般情况用分类好,用Category去重写类的方法,仅对本Category有效,不会影响到其他类与原有类的关系. NSDate+Category.h 代码: #import & ...

  6. 关于Retrofit + RxJava 的使用

    年前一个月到现在,一直都在忙一个项目.项目使用的三方框架还是蛮多的. 下面来总结一下自己使用Retrofit + RxJava的知识点吧. (以下讲述从一个请求的最初开始) 1.首先定义一个RxMan ...

  7. COGS 788. 昵称

    788. 昵称 ★☆   输入文件:nickname.in   输出文件:nickname.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] ZSUQ送信者与腾讯QQ相似 ...

  8. initWithNibName/awakeFromNib/initWithCoder

    转自: http://leeyin.iteye.com/blog/1040362 每个ios开发者对loadView和viewDidLoad肯定都很熟悉,虽然这两个函数使用上真的是非常简单,但是和类似 ...

  9. java 中设计模式

    1. 单例模式(一个类只有一个实例) package ch.test.notes.designmodel; /** * Description: 单例模式 (饿汉模式 线程安全的) * * @auth ...

  10. Ajax 发送OPTION请求

    从fetch说起,用fetch构造一个POST请求. fetch('http://127.0.0.1:8000/api/login', { method: "POST", head ...