怒刷DP之 HDU 1069
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
prayerhgq (2015-08-04)
System Crawler (2015-09-05)
Description
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
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
Sample Input
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 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <climits>
using namespace std; const int SIZE = ;
int COUNT,DP[SIZE];
struct Node
{
int x,y,z;
}S[SIZE]; void ex(const Node &);
bool comp(const Node & r_1,const Node & r_2);
int main(void)
{
int n,count = ; while(scanf("%d",&n) != EOF && n)
{
count ++;
COUNT = ;
fill(DP,DP + SIZE,);
for(int i = ;i < n;i ++)
{
scanf("%d%d%d",&S[COUNT].x,&S[COUNT].y,&S[COUNT].z);
ex(S[COUNT]);
}
sort(S,S + COUNT,comp); int ans = -;
for(int i = ;i < COUNT;i ++)
{
DP[i] = S[i].z;
int max = -;
for(int j = i - ;j >= ;j --)
if(S[j].x < S[i].x && S[j].y < S[i].y)
max = max > DP[j] ? max : DP[j];
if(max != -)
DP[i] += max;
ans = ans > DP[i] ? ans : DP[i];
}
printf("Case %d: maximum height = %d\n",count,ans);
} return ;
} void ex(const Node & r)
{
++ COUNT;
S[COUNT] = r;
swap(S[COUNT].y,S[COUNT].z); ++ COUNT;
S[COUNT] = r;
swap(S[COUNT].x,S[COUNT].y); ++ COUNT;
S[COUNT] = S[COUNT - ];
swap(S[COUNT].y,S[COUNT].z); ++ COUNT;
S[COUNT] = S[COUNT - ];
swap(S[COUNT].x,S[COUNT].z); ++ COUNT;
S[COUNT] = S[COUNT - ];
swap(S[COUNT].y,S[COUNT].z); ++ COUNT;
} bool comp(const Node & r_1,const Node & r_2)
{
if(r_1.x == r_2.x)
return r_1.y < r_2.y;
return r_1.x < r_2.x;
}
怒刷DP之 HDU 1069的更多相关文章
- 怒刷DP之 HDU 1257
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- 怒刷DP之 HDU 1160
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- 怒刷DP之 HDU 1260
Tickets Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- 怒刷DP之 HDU 1176
免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 怒刷DP之 HDU 1087
Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ...
- 怒刷DP之 HDU 1114
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- 怒刷DP之 HDU 1024
Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 怒刷DP之 HDU 1029
Ignatius and the Princess IV Time Limit:1000MS Memory Limit:32767KB 64bit IO Format:%I64d &a ...
- HDU 1069 dp最长递增子序列
B - Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
随机推荐
- jsp转发action的问题找不到acton
-----------------------------jsp转发action的问题找不到acton------------------------------------------- jsp: ...
- getName()、getCanonicalName()、getSimpleName()异同
package classes; class Box { class Inner { } } public class TestGetName { public static void main(St ...
- Lucene/ElasticSearch 学习系列 (2) Information Retrival 初步之名词解释
计算机领域一半是理论,一半是在理论基础之上的应用.要想深入地掌握某个方面的应用,就需要先学习那方面的理论. “搜索”是应用,其背后的理论是 "Information Retrieval&qu ...
- 自定义Template,向其中添加新的panel
参考网站:https://www.devexpress.com/Support/Center/Example/Details/E2690 思路: 新建一个DefaultTemplate: ...
- (剑指Offer)面试题28:字符串的排列
题目: 输入一个字符串,打印出该字符串中字符的所有排列. 例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 思路: 把一个字符串看 ...
- ExtJs非Iframe框架加载页面实现
在用Ext开发App应用时,一般的框架都是左边为菜单栏,中间为tab页方式的显示区域.而tab页面大多采用的嵌入一个iframe来显示内容.但是采用iframe方式有一个很大的弊端就是每次在加载一个新 ...
- Linux 卸载Oracle 11G
卸载oracle11G数据 1.使用SQL*PLUS停止数据库[oracle@OracleTest oracle]$ sqlplus /nologSQL> connect / as sysdba ...
- 学习马士兵的struts2/hibernate/spring中遇到的问题及其解决方法
STRUTS2 1. 写好最简单的hello world项目后,无法通过浏览器访问到hello.jsp页面,提示没有资源. 学习structs2的时间,已经更新到了2.3.16了,structs中的很 ...
- 组件化CSS--管理你整站的CSS文件
为什么要拆分样式文件? 更易于查找样式规则. 简化维护,方便管理. 还可以针对某一页面提供特定的样式. 为什么要添加桥接样式? 你可以随时添加或移除样式而不需要修改HTML 文档. 为什么要定义两种媒 ...
- influxdb Measurements
第一次看influxdb的代码实例时不明白influxdb Measurements是什么意思.经过研究总结一下. 1)measurement,相当于关系数据库中的table,包含tag,field, ...