kuangbin专题十二 HDU1069 Monkey and Banana (dp)
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
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.
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.
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 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)的更多相关文章
- kuangbin专题十二 POJ1661 Help Jimmy (dp)
Help Jimmy Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14214 Accepted: 4729 Descr ...
- kuangbin专题十二 HDU1176 免费馅饼 (dp)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU1069 Monkey and Banana —— DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS ...
- kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)
Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7949 Accepted: 42 ...
- kuangbin专题十二 HDU1029 Ignatius and the Princess IV (水题)
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- kuangbin专题十二 HDU1260 Tickets (dp)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- kuangbin专题十二 HDU1114 Piggy-Bank (完全背包)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- kuangbin专题十二 HDU1074 Doing Homework (状压dp)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- leetcode230
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...
- MySQL学习笔记之一---字符编码和字符集
前言: 一般来说,出现中文乱码,都是客户端和服务端字符集不匹配导致的原因. (默认未指定字符集创建的数据库表,都是latinl字符集, 强烈建议使用utf8字符集) 保证不出现乱码的思想:保证客户 ...
- C#高级参数ref的使用
ref关键字用于将方法内的变量改变后带出方法外.具体我们通过例子来说明: 例子中,将变量n1和n2交换了.如果没有加ref参数,由于没有swadDemo()方法没有返回值,调用后,n1和n2是不会交换 ...
- tomcat使用manager管理app时需要身份验证问题
我们可以通过图形用户界面来管理tomcat,启动tomcat,在地址栏中输入: Java代码 http://localhost:8080 就可以看见tomcat的欢迎页面,点击左边的tomcat ma ...
- SQL基础E-R图基础
ER图分为实体.属性.关系三个核心部分.实体是长方形体现,而属性则是椭圆形,关系为菱形. ER图的实体(entity)即数据模型中的数据对象,例如人.学生.音乐都可以作为一个数据对象,用长方体来表示, ...
- 无人驾驶——4.控制之MPC模型预测控制
源自:<无人驾驶无人驾驶车辆模型预测控制>——龚建伟 参考:https://wenku.baidu.com/view/8e4633d519e8b8f67c1cb9fa.html 0.车辆模 ...
- iOS 列表三级展开
效果图如下: #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDe ...
- CF438D The Child and Sequence
外国人的数据结构题真耿直 唯一有难度的操作就是区间取模,然而这个东西可以暴力弄一下,因为一个数$x$被取模不会超过$logn$次. 证明如下(假设$x Mod y$): 如果$y \leq \fr ...
- Django框架 之 admin管理工具(源码解析)
浏览目录 单例模式 admin执行流程 admin源码解析 单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在.当你希望在 ...
- PartyLocation的Post请求问题---debug
这里,遇到了一个debug: @Override public void setPrimaryPartyLocation(PartyLocation partyLocation) { if (!get ...