HDU 1069 Monkey and Banana(动态规划)
Monkey and Banana
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.
题目大意:给出箱子的长、宽、高,每个箱子有很多种,然后求叠起来的最大高度,上边箱子的长和宽必须小于下边的箱子
代码如下:
# include <iostream>
# include<cstdio>
# include<cstring>
# include<cstdlib>
using namespace std;
struct node
{
int x,y,z;
} s[]; int cmp(const void *a,const void *b)
{
struct node* aa = (node *)a;
struct node* bb = (node *)b;
if(aa->x != bb->x)
return aa->x - bb->x;
else if(aa->y != bb->y)
return aa->y - bb->y;
return aa->z - bb->z;
}
int dp[];
int main()
{
int n,i,j,a,b,c;
int cas = ;
while(scanf("%d",&n)&&n)
{
for(i=; i<n; i++)
{
scanf("%d%d%d",&a,&b,&c);
s[i*].x = a; s[i*].y = b; s[i*].z = c;
s[i*+].x = a; s[i*+].y = c; s[i*+].z = b;
s[i*+].x = b; s[i*+].y = a; s[i*+].z = c;
s[i*+].x = b; s[i*+].y = c; s[i*+].z = a;
s[i*+].x = c; s[i*+].y = a; s[i*+].z = b;
s[i*+].x = c; s[i*+].y = b; s[i*+].z = a;
}
qsort(s,n*,sizeof(s[]),cmp);
for(i=; i<*n; i++)
dp[i] = s[i].z;
int ans = ;
for(i=; i<n*; i++)
{
for(j=; j<i; j++)
{
if(s[i].x > s[j].x && s[i].y > s[j].y && dp[j]+s[i].z > dp[i])
dp[i] = dp[j]+s[i].z ;
}
if(dp[i]>ans)
ans = dp[i];
}
printf("Case %d: maximum height = %d\n",cas++,ans);
}
return ;
}
HDU 1069 Monkey and Banana(动态规划)的更多相关文章
- HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)
HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
- HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana(二维偏序LIS的应用)
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069—— Monkey and Banana——————【dp】
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1069 Monkey and Banana
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana(DP 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
随机推荐
- 从最近MySQL的优化工作想到的
最近决定将以前同事写的存储过程查看一遍,寻找一些代码上写的不太好的地方,争取进行修改以后让这些过程达到一个很好的运行速度.下面是遇到的最多的几个问题. 我遇到了这样的一个SQL: select nam ...
- 记一次js中和php中的字符串长度计算截取的终极问题和完美解决方案
1.js是用unicode算长度的,比如单字节的算1,中文也算1,但是正常我们想让两个单字节算1,如何计算这个长度 第一种解决方案,用正则,如下 /[\u0x00-\u0xff]/,天真的想着,这样就 ...
- ios基础知识
1获取系统语言设置 NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSArray *languages = ...
- 【Android 应用开发】Activity 状态保存 OnSaveInstanceState參数解析
作者 : 韩曙亮 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/38297083 一. 相关方法简单介绍 1. 状态保存方法演示 ...
- 成员方法与const之间的关系
const可以放在成员方法的三个地方,前.中.后. 首先考虑在中间: 1.const修饰形参,表示形参是否为const 2.如果const修饰引用(指针指向的对象),可以进行过载,如果不是修饰引用(指 ...
- 看原理图之UART
UART原理 协议类之间的通信就跟人之间交流一样,要遵守一定的原则:1.你说的话别人得听得懂,不能有语言障碍:2.你不能说的太快,别人都来不及反应. 对上面的话用专业点的语句描述下就是: 1.双方约定 ...
- Mysql 5.5 replication 多数据库主从备份Master-Slave配置总结
配置Mysql server 5.5 的双机备份,也就是master-slave模式.本例子还是一个多database复制的情况. 现在有两个database在同一台mysql server,也就是m ...
- 启动和启动和停止MySQL服务停止MySQL服务
1. 启动MySQL服务 启动MySQL服务的命令为: /etc/init.d/mysqld start 命令执行后如图7-5所示,表示启动MySQL服务成功. (点击查看大图)图7-5 启动 ...
- CSS3 动态魔方的展示
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jquery用on代替bind(),live(),delegate()的方法
Js的功能确实非常强大,奈何我一个php程序员一直在js上没有投入足够的精力去研究,每次遇到不会的都是去百度,以后有时间真的应该买本书系统的学习一下 // Bind $( "#members ...