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. storm trident的filter和函数

    目的:通过kafka输出的信息进行过滤,添加指定的字段后,进行打印 SentenceSpout: package Trident; import java.util.HashMap; import j ...

  2. texlive安装

    本人电脑系统win8.1,安装texlive2016的时候报错"Can't spawn "cmd.exe": No such file or directory at.. ...

  3. 最小化安装centos后ifconfig看不到eth0

    最小换安装centos后,ifconfig看不到eth0,只看到一个lo ifup eth0

  4. Windows系统下Android开发环境搭建

    “工具善其事,必先利其器”.要想学好Android,搭建好Android开发环境是一个良好的开端. Windows系统下Android开发环境主要有4个大的步骤.分别是: 1.JDK的安装 2.ecl ...

  5. svn merge当主干修改后合并分支

    例如版本r1的主干创建分支r2,在r2上修改后得到r3,r1之后也修改得到r4,现在合并分支到主干上: 如果r3的修改和r4有冲突会提示出现冲突,因此不用担心主干合并后会被分支操作覆盖,因为这并不是简 ...

  6. shell框架

    #!/bin/bash#注释#注释#环境变量相关,如下PATH=/sbin:/bin:/usr/bin:/usr/sbin #引入库函数,如下,类似于c语言的#include "*.h&qu ...

  7. MYSQL 中随机读取一条数据

    SELECT * FROM res AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM res) - (SELECT MIN(id) FRO ...

  8. 清空iptables

    /sbin/iptables -P INPUT ACCEPT /sbin/iptables -F iptables -L

  9. 美国司法部解禁guns打印技术

    今日导读 你知道什么是 3D 打印吗?简单的说,只要有一张设计蓝图和适当的材料,就可以快速打印出实体物件.而最近据外媒报道,从今年 8 月 1 日起,在美国,拥有或公布枪支 3D 打印蓝图的行为都将属 ...

  10. 洛谷五月月赛【LGR-047】划水记

    虽然月赛有些爆炸,但我永远资瓷洛谷! 因为去接水,所以迟到了十几分钟,然后洛谷首页就打不开了-- 通过洛谷题库间接打开了比赛,看了看\(TA\),WTF?博弈论?再仔细读了读题,嗯,判断奇偶性,不过要 ...