hdu1069 最长上升子序列变形
来源:互联网 发布:ip网络广播软件源文件 编辑:程序博客网 时间:2024/06/09 19:20
Monkey and Banana
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种立方体(个数无限),长宽高已知,叠放的要求是每个长方体的长和宽必须小于他下面的长方体,求叠出高度的最大值。
思路:虽然说长方体个数无限但是一个长方体最多出现3次,否则必定无法叠放。类似于矩形嵌套问题。对一个长方体的长排序,然后对宽进行比较,判断能否放入。对高度进行dp判断。
代码:
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int N=200;struct node{ int x,y; int h; node(){x=0,y=0,h=0;} node(int a,int b,int c):x(a),y(b),h(c){}}st[N];int dp[N];bool cmp(node n1,node n2){ return n1.x<n2.x;}int main(){ int n; int ca=1; while(scanf("%d",&n),n) { int x,y,z; memset(dp,0,sizeof(dp)); for(int i=1,j=0;i<=n;i++) { scanf("%d%d%d",&x,&y,&z); st[++j]=node(x,y,z); st[++j]=node(y,x,z); st[++j]=node(y,z,x); st[++j]=node(z,y,x); st[++j]=node(z,x,y); st[++j]=node(x,z,y); } sort(st+1,st+6*n+1,cmp); int ans=0; for(int i=1;i<=6*n;i++){ dp[i]=st[i].h; for(int j=1;j<i;j++)if(st[i].x!=st[j].x&&st[j].y<st[i].y){ dp[i]=max(dp[i],dp[j]+st[i].h); } ans=max(dp[i],ans); } printf("Case %d: ",ca++); printf("maximum height = %d\n",ans); } return 0;}
- hdu1069 最长上升子序列变形
- hdu1069-最长连续上升子序列
- HDU1069 最长单调子序列变形
- 合唱队形---最长上升子序列变形
- 最长上升子序列的变形
- hdu4512(最长上升公共子序列变形)
- poj3616(最长上升子序列变形)
- hdu5489(最长上升子序列变形)
- hdu1160(最长上升子序列变形)
- 【HDU】5256 序列变换(最长上升子序列变形)
- uva 1471 - Defense Lines (最长上升子序列变形)
- poj1836--Alignment(dp,最长上升子序列变形)
- poj1836--Alignment(dp,最长上升子序列变形)
- hdu 1069 dp入门 最长上升子序列变形
- uva1471 - Defense Lines (最长上升子序列变形)
- POJ 1836 Alignment LIS变形(最长上升子序列)
- HDU 1025 最长上升子序列变形 (dp+二分)
- nyist 16 矩形嵌套(最长上升子序列变形)
- 企业架构
- android程序出错了怎么更友好的处理
- 14、UI_02拨号盘动画
- iOS数据库SQLite
- Android Studio 初体验(So库的添加)
- hdu1069 最长上升子序列变形
- 千里码第一题
- 使用 Navicat111_premium 将 oracle 数据库迁移到 mysql
- iOS NSUserDefaults
- ASIHTTPRequest 提示#import <libxml/HTMLparser.h>找不到
- 【视频】Excel2013十大企业级明星函数视频课程【精讲】
- HDU5592(线段树+二分)
- iOS中int,float怎么保存在NSMutableArray中
- 简单的数据查询