怒刷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 ...
随机推荐
- My集合框架第二弹 二叉树的实现
package com.wpr.collection; import java.util.NoSuchElementException; public class BinarySearchTree&l ...
- jquery操作复选框(checkbox)
1.获取单个checkbox选中项(三种写法)$("input:checkbox:checked").val()或者$("input:[type='checkbox']: ...
- c# abstract抽象类与继承类子类的构造函数_base
http://blog.itpub.net/9240380/viewspace-718054/ http://blog.163.com/cloud_thegreat/blog/static/10367 ...
- DOM2
DOM级别 文档类型: 节点类型: 判断节点类型(注意Node对象): <div id="container">这是一个元素节点</div> <scr ...
- MySQL中MySQL X.X Command Line Client一闪而过的问题
问题介绍:我安装完MySQL(我安装的是5.5)后,使用MySQL 5.5 Command Line Client,每次点击,总是一闪而过.解决方法如下: 首先进入cmd 切入MySQL的安 ...
- C# GDI在控件上绘图
本文以以在chart控件上和窗体上画矩形为例子 不多解释了,代码很简单. 还有一些童鞋要别的源码,给我发邮箱吧 using System; using System.Collections.Gener ...
- 【ArcGIS 10.2新特性】Portal for ArcGIS新特性
1.概述 经过各版本的积累和更新,Portal for ArcGIS在ArcGIS10.2中以正式产品的形态加入到了ArcGIS系列产品线中.它有3个主要定位:协同管理平台.在线制图平台以及内容管理平 ...
- C++ 内存泄露处理方法 (转)
1.可以显示内存泄露情况,但无法找到具体的文件位置写法 包含头文件#include <crtdbg.h> 然后在需要检测内存泄露的位置加上语句 _CrtDumpMemoryLeaks(); ...
- BackTrack5 (BT5)无线password破解教程之WPA/WPA2-PSK型无线password破解
昨天公布了BackTrack5 (BT5)无线weppassword破解教程之minidwep-gtk破解法一文,对BT5下破解wep无线password的简单方法做了介绍,今天奶牛为朋友们介绍下怎样 ...
- 使用NPOI导出DataTable到Excel
使用C#对DataTable导出到Excel是我们工作当中比较多用到的场景,微软提供了Microsoft.Office.Interop.Excel组件可以进行操作,但是该组件在数据量大的时候速度很慢, ...