Monkey and Banana dp
来源:互联网 发布:福建随行软件 编辑:程序博客网 时间:2024/05/19 02:18
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 Sample Output
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
题意:给定n种立方体,要求摆成塔状(上面的长宽都小于下面的),求最大高度。
每个立方体我们都可以用不同的方向做高,所以可以当三个来用(长大于宽)
我们再根据只能小的放在大的上面,进行排序,排完后,我们依次去放就行,只要满足,取最高的情况
#include<iostream>#include<cstring>#include<cmath>#include<algorithm>using namespace std;struct f{int l,w,h;}a[110];int dp[110];bool cmp(f a,f b ){if(a.l>b.l) return 1;if(a.l==b.l&&a.w>b.w) return 1;return 0;}int main() {std::ios::sync_with_stdio(false);int n,Case=1;while(cin>>n) {if(n==0) break; int d[3],m=0,Max=0;for(int i=0;i<n;i++){dp[i]=0;cin>>d[0]>>d[1]>>d[2];sort(d,d+3);a[m].h=d[0];a[m].l=d[2];a[m].w=d[1];m++;a[m].h=d[1];a[m].l=d[2];a[m].w=d[0];m++;a[m].h=d[2];a[m].l=d[1];a[m].w=d[0];m++;}sort(a,a+m,cmp);for(int i=0;i<m;i++) dp[i]=a[i].h; for(int i=1;i<m;i++){ for(int j=0;j<i;j++){ if(a[i].l<a[j].l&&a[i].w<a[j].w) dp[i]=max(dp[i],dp[j]+a[i].h);}Max=max(Max,dp[i]);} cout<<"Case "<<Case++<<": maximum height = "<<Max<<endl;}}
阅读全文
0 0
- Monkey and Banana dp
- Monkey and Banana(dp)
- HDU1069(Monkey and Banana)DP
- hdoj1069 Monkey and Banana (dp)
- HDU1069 Monkey and Banana 【DP】
- HDOJ1069-Monkey and Banana(DP)
- HDOJ1069 Monkey and Banana【dp】
- hdu1069 Monkey and Banana--DP
- Monkey and Banana(DP)
- HDU1069-Monkey and Banana(dp)
- hdu1069 Monkey and Banana dp
- hdoj1069 Monkey and Banana(DP)
- zoj 1093 dp Monkey and Banana
- ZOJ 1093 Monkey and Banana (DP)
- ZOJ 1093 Monkey and Banana【DP】
- hdu1069 Monkey and Banana 还是DP
- hdu 1069 Monkey and Banana (DP)
- hdu 1069 Monkey and Banana(dp)
- Mysql学习总结(12)——21分钟Mysql入门教程
- Girls and Boys
- 170929 逆向-Reversing.kr(Ransomware)
- 九个jsp内置对象
- 生活小记19
- Monkey and Banana dp
- Atom中七牛图床配置+解决无法上传的问题
- ros文件系统
- BZOJ 1029 建筑抢修 (贪心)
- 第五章 编写主引导扇区代码
- 21分钟Mysql入门教程--对前面的命令摘录
- 编译安装httpd,nginx,mysql,yum命令详解
- Ubuntu16.04安装MySQL数据库和可视化工具MySQL Workbench
- Q:JDK6中的substring()方法容易导致内存泄露而JDK7不会出现这样的情况的原因