Monkey and Banana
Time Limit: 2000/1000 MS
(Java/Others)
Total Submission(s): 2567
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.
在这里杭电里划水,嘿嘿,发现自己真是一只菜鸟,此题目考察到动态规划里的最长有序子序列,
题目的意思是:
有n种长方体,每种长方体都有无限多个,问用这些长方体最高能摆多高?要求:下面的长方体的长大于上面长方体的长,宽大于上面长方体的宽;
解题思路:
因为每种长方体最多只能用两次,但却不知道用的是哪个面做的底面,所以要把每个长方体存三次,且
x,y,z,必须满足x>y,||x<y,为了判断是方便,之后,对每个长方体按底面面积从大到小或是从小到大排序;接下来就是最长有序子序列的做法了,这就不多说了;
代码如下:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct stu{
}s[1000];
int cmp1(const void*a,const void*b)
{
}
int cmp2(const void*a,const void*b)
{
}
int main()
{
}