nyoj How to eat more Banana (LIS变型&&DP)好题
来源:互联网 发布:淘宝手机详情图片模糊 编辑:程序博客网 时间:2024/05/22 14:53
How to eat more Banana
时间限制:1000 ms | 内存限制:65535 KB
难度:4
- 描述
- 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.- 输入
- 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. - 输出
- 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".
- 样例输入
110 20 3026 8 105 5 571 1 12 2 23 3 34 4 45 5 56 6 67 7 7531 41 5926 53 5897 93 2384 62 6433 83 270
- 样例输出
Case 1: maximum height = 40Case 2: maximum height = 21Case 3: maximum height = 28Case 4: maximum height = 342
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;struct zz{int x;int y;int z;}q[110];int cmp(zz a, zz b){if(a.x==b.x)return a.y<b.y;return a.x<b.x;}int b[110];int main(){int T=1;int n,i,j,k,l;int x,y,z;while(scanf("%d",&n),n){k=0;while(n--){scanf("%d%d%d",&x,&y,&z);q[k].x=max(x,y);q[k].y=min(x,y);q[k++].z=z;//关键点是这块的转换 q[k].x=max(x,z);q[k].y=min(x,z);q[k++].z=y;q[k].x=max(y,z);q[k].y=min(y,z);q[k++].z=x;}sort(q,q+k,cmp);for(i=0;i<k;i++)b[i]=q[i].z;int mm=b[0];for(i=1;i<k;i++){for(j=0;j<i;j++){if(q[j].x<q[i].x&&q[j].y<q[i].y&&b[j]+q[i].z>b[i])b[i]=b[j]+q[i].z;}if(mm<b[i])mm=b[i];}printf("Case %d: maximum height = %d\n",T++,mm);}return 0;}
0 0
- nyoj How to eat more Banana (LIS变型&&DP)好题
- nyoj232 How to eat more Banana (LIS变形)
- nyoj 232 How to eat more Banana
- How to eat more Banana(nyoj 232)
- How to eat more Banana
- How to eat more Banana
- NY-232 How to eat more Banana
- UVa 437 The Tower of Babylon & NYOJ 232 How to eat more Banana
- CodeForces - 582B Once Again... (LIS变型)好题
- nyoj How many ways?? 2157 (DP) 好题
- nyoj Vawio Sequence 763 (STL) LIS变型
- HDOJ1069 Monkey and Banana(DP,LIS)
- nyoj See LCS again 760 (LCS&&LIS) 好题
- How to Eat an Elephant
- HDU 1069 Monkey and Banana DP LIS
- 【DP|LIS】HDU-1069 Monkey and Banana
- 【BZOJ4300】绝世好题【DP】【LIS】
- nyoj 又见拦截导弹 814 (DP+LIS)
- 公开密匙(public key)和专用密匙(private key)
- Java多线程用法解析
- Android退出应用的几种方式
- Tomcat上运行正常,部署在weblogic服务器上,不认jsp等标签问题
- iptables的五个关口
- nyoj How to eat more Banana (LIS变型&&DP)好题
- 圆明园记
- Java 多线程 并发编程
- Android DraerLayout 抽屉百分比适配屏幕宽度
- linux系统fdisk分区过程-46
- hdoj5400Arithmetic Sequence【等差数列】
- ajax文件上传步骤详解
- 专访搜狗DBA负责人王林平:为何从Oracle转向MySQL?
- perl 重复编码转换问题,没有影响