Monkey and Banana HDU
来源:互联网 发布:做淘宝客服的流程 编辑:程序博客网 时间:2024/05/17 10:08
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 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.
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<bits/stdc++.h>using namespace std;struct aa{ int c,k,g;} save[100];int dp[300];bool cmp(const aa &a,const aa &b){ int m=max(a.c,a.k); int n=max(b.c,b.k); return m>n;}int main(){ int n; int kase=1; while(scanf("%d",&n)!=EOF&&n) { memset(dp,0,sizeof(dp)); int m=1; for(int i=0; i<n; i++) { int c,k,g; scanf("%d%d%d",&c,&k,&g); save[m].c=c,save[m].k=k,save[m++].g=g; save[m].c=c,save[m].k=g,save[m++].g=k; save[m].c=k,save[m].k=g,save[m++].g=c; } sort(save+1,save+1+m,cmp); int maxxx=-1; for(int i=1; i<m; i++) { int maxx=0; for(int j=i-1; j>=1; j--) { if((save[i].c<save[j].c&&save[i].k<save[j].k)||(save[i].c<save[j].k&&save[i].k<save[j].c)) { maxx=max(maxx,dp[j]); } } dp[i]=maxx+save[i].g; maxxx=max(maxxx,dp[i]); } printf("Case %d: maximum height = %d\n",kase++,maxxx); }}
阅读全文
1 0
- hdu -Monkey and Banana
- HDU-Monkey and Banana
- Monkey and Banana HDU
- Monkey and Banana HDU
- Monkey and Banana HDU
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and banana
- hdu 1069 Monkey and Banana
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- 动规路 HDU (Monkey and Banana)
- hdu 1069 Monkey and Banana
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- 冒泡排序将输入框的数字排序(结合angular.js)
- Android Intent.FLAG_NEW_TASK详解,包括其他的标记的一些解释
- linux 普通用户登录后,执行 shell脚本切自动输入密码切换到root
- 内核空间vmalloc的空间初始化
- svn 命令行下常用的几个命令
- Monkey and Banana HDU
- 生成二维码
- 超链接QTable实现
- 基于sklearn的文本特征提取与分类
- 关于折行的问题
- 详解servlet的生命周期
- hbase SQL 框架phoenix使用
- 分布式架构的演进
- File文件的操作过滤