Monkey and Banana

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20094    Accepted Submission(s): 10725

Problem Description
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.

 
Input
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.
 
Output
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".
 
Sample Input
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
 
Sample Output
Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
 

题目大意:给出n种长方体的x,y,z(任意个),然后堆起来(要求严格小于自己下面的长方体),求能达到的最大高度。

经典的矩形嵌套:把每种长方体的6种方法都存储起来,然后排序,然后再像上升子序列dp一样。见注释

 #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define forn(i, x, n) for(int i = (x); i < n; i++)
#define nfor(i, x, n) for(int i = n-1; i >= x; i--)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF =0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-;
const ll mod = 1e9+; struct node{
int l, w, h;
}stu[];
int dp[];//dp[i] 表示 i能达到的最高高度 bool cmp(node a, node b) {//先x 后 y
if(a.l == b.l)
return a.w < b.w;
return a.l < b.l;
} int main() {
int n, x, y, z, cur;
int icase = ;
while(~scanf("%d", &n),n) {
cur = ;
while(n--) {
scanf("%d%d%d", &x, &y, &z);//存储6种状态
stu[cur].l = x; stu[cur].w = y; stu[cur++].h = z;
stu[cur].l = x; stu[cur].w = z; stu[cur++].h = y;
stu[cur].l = y; stu[cur].w = z; stu[cur++].h = x;
stu[cur].l = y; stu[cur].w = x; stu[cur++].h = z;
stu[cur].l = z; stu[cur].w = x; stu[cur++].h = y;
stu[cur].l = z; stu[cur].w = y; stu[cur++].h = x;
}
sort(stu, stu+cur, cmp);//排序
mem(dp, );
int maxx = -inf;
forn(i, , cur) {
dp[i] = stu[i].h;//初始化
forn(j, , i) {//找到使自己最高的
if(stu[j].l < stu[i].l && stu[j].w < stu[i].w) {
dp[i] = max(dp[j] + stu[i].h, dp[i]);
}
}
maxx = max(maxx, dp[i]);//更新最高高度
}
maxx = max(, maxx);
printf("Case %d: maximum height = %d\n", icase++, maxx);
}
}

kuangbin专题十二 HDU1069 Monkey and Banana (dp)的更多相关文章

  1. kuangbin专题十二 POJ1661 Help Jimmy (dp)

    Help Jimmy Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14214   Accepted: 4729 Descr ...

  2. kuangbin专题十二 HDU1176 免费馅饼 (dp)

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  3. HDU1069 Monkey and Banana —— DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS ...

  4. kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)

    Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7949   Accepted: 42 ...

  5. kuangbin专题十二 HDU1029 Ignatius and the Princess IV (水题)

    Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K ( ...

  6. kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)

    FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  7. kuangbin专题十二 HDU1260 Tickets (dp)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  8. kuangbin专题十二 HDU1114 Piggy-Bank (完全背包)

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. kuangbin专题十二 HDU1074 Doing Homework (状压dp)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. suse 源的添加与删除,以及源地址

    地址 一个是上海交大的,http://ftp.sjtu.edu.cn/opensuse/update/ 葡萄牙的: http://ftp.nux.ipb.pt/pub/dists/opensuse/u ...

  2. BA 新web化 问题汇总

    1. 3D堆栈图在winform端无法显示,但在web端可以正常显示,说明与浏览器版本有关,在 IE 中设置文档模式为 IE8 即报错,IE9 却正常显示,可在 <head>节点下添加如下 ...

  3. 问题:System.Guid.NewGuid();结果:C# System.Guid.NewGuid()

    C# System.Guid.NewGuid() 概念 GUID: 即Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique I ...

  4. Diag:Diagonal matrices and diagonals of a matrix

    Diag:Diagonal matrices and diagonals of a matrix Syntax X = diag(v,k) X = diag(v) v = diag(X,k) v =  ...

  5. 恢复oracle的回收站的所有的表

    使用sys as sysdba 进入到sqlplus的控制界面 sqlplus / as sysdba 执行相关的命令,自动生成一个脚本文件 spool d:/a.sql select 'flashb ...

  6. HDU 6162 树链剖分

    题意:给你一颗树,每个节点有有一个权值,每次询问从x到y的最短路上权值在c到d之间的所有的点的权值和是多少. 思路:肯定要用树剖,因为询问c到d之间这种操作树上倍增很难做,但是用其它数据结构可以比较好 ...

  7. jquery easyui datagrid/table 右边线显示不全

    <table id="dg" style="height:400px"></table> 右边线显示不全 解决:在外面套一个panel, ...

  8. Python 网络爬虫 002 (入门) 爬取一个网站之前,要了解的知识

    网站站点的背景调研 1. 检查 robots.txt 网站都会定义robots.txt 文件,这个文件就是给 网络爬虫 来了解爬取该网站时存在哪些限制.当然了,这个限制仅仅只是一个建议,你可以遵守,也 ...

  9. K-D TREE算法原理及实现

    博客转载自:https://leileiluoluo.com/posts/kdtree-algorithm-and-implementation.html k-d tree即k-dimensional ...

  10. 高性能MySQL笔记-第5章Indexing for High Performance-003索引的作用

    一. 1. 1). Indexes reduce the amount of data the server has to examine.2). Indexes help the server av ...