HDU 1069 Monkey and Banana(线性DP)
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.
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.
The input file will contain one or more test cases. The first line of each test case contains an integer 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".
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
#include <bits/stdc++.h>
using namespace std;
struct rectangle
{
int x;
int y;
int z;
int size;
};
bool cmp(rectangle a,rectangle b)
{
// if(a.x!=b.x)return a.x>b.x;
// else return a.y>b.y;
return a.size>b.size;
}
vector<rectangle>v;
int n;
//dp[i]:以第i个为顶的最大高度 dp[i]=max(dp[i],dp[k]+h[i])
int dp[]; int main()
{
int i,j;
int cnt=;
while(scanf("%d",&n)&&n)
{
cnt++;
v.clear();
rectangle occ;
v.push_back(occ);
for(i=;i<=n;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
rectangle temp;
temp.z=x;
temp.x=max(y,z);
temp.y=min(y,z);
temp.size=y*z;
v.push_back(temp);
temp.z=y;
temp.x=max(x,z);
temp.y=min(x,z);
temp.size=x*z;
v.push_back(temp);
temp.z=z;
temp.x=max(x,y);
temp.y=min(x,y);
temp.size=x*y;
v.push_back(temp);
}
sort(v.begin()+,v.end(),cmp);//不要sort占位的
for(i=;i<v.size();i++)//初始化!!假设一个长方体没有任何底座,他自己的高就是最终的高
{
dp[i]=v[i].z;
}
int ans=dp[];
for(i=;i<v.size();i++)
{
for(j=;j<i;j++)//只有i之前的能作为底座
{
if(v[j].x>v[i].x&&v[j].y>v[i].y)
{
dp[i]=max(dp[i],dp[j]+v[i].z); }
ans=max(ans,dp[i]);
}
} printf("Case %d: maximum height = %d\n",cnt,ans);
}
return ;
}
HDU 1069 Monkey and Banana(线性DP)的更多相关文章
- 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 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...
- HDU 1069 Monkey and Banana(DP——最大递减子序列)
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 题意描述: 给n块砖,给出其长,宽和高 问将这n块砖,怎样叠放使得满足以下条件使得 ...
- HDU 1069 Monkey and Banana (dp)
题目链接 Problem Description A group of researchers are designing an experiment to test the IQ of a monk ...
- HDU 1069 Monkey and Banana ——(DP)
简单DP. 题意:给出若干种长方体,如果摆放时一个长方体的长和宽小于另一个的长宽,那么它可以放在另一个的上面,问最高能放多少高度.每种长方体的个数都是无限的. 做法:因为每种个数都是无限,那么每种按照 ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- 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(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- Ubuntu18.04 一条命令安装caffe问题
由于caffe安装坑很多,而且caffe框架很久不更新了,微调对框架影响不大,所以对与ubuntu18.04在caffe官网提供了一条命令安装,避免很多踩坑痛苦. CPU的一条命令安装: sudo a ...
- 电脑进不去BIOS解决办法
把所有外设(主要是硬盘,包括装在主板上的固态硬盘)拆下来,拆下纽扣电池给主板放电,装回纽扣电池,重启F1进入BIOS. 最终查到原因,是固态那里出的问题,固态作为启动硬盘,被自己搞得有问题了,有两个启 ...
- (转)Boyer-Moore算法
转自:Boyer-Moore算法 一.简述 在当前用于查找子字符串的算法中,BM(Boyer-Moore)算法是当前有效且应用比较广的一中算法,各种文本编辑器的“查找”功能(Ctrl+F),大多采用B ...
- AM335X的应用程序自启动流程以及U盘更新应用程序记录
在AM335X的SD卡更新系统学习记录中最后更新完系统后,以后运行应用程序都会从EMMC中取出Linux系统运行.接着介绍Linux系统是怎么自己启动我们编写的应用程序的. 1.在AM335X的SD卡 ...
- C#的HttpModule中及Java的Servlet中成员变量乱用导致的不易重现的BUG
3年前写的在HttpModule中记录访问日志的代码,在最近使用日志数据分析登录账号的IP情况时,才发现了一个不易重现的BUG——日志中记录的登录账号出现串掉的情况.之所以这个时候才发现该问题,是因为 ...
- 0107 spring操作数据库的3个架子
背景 数据库开发是java的核心内容之一,基础就是jdbc了: 然而直接使用jdbc,需要写大量的try-catch-finally模板代码: 管理系统使用hibernate作为orm框架比较方便,遵 ...
- 关于button在td中时,zclip复制不能的问题
是button的定位问题引起的,解决方案:套上div加上position:relative即可 <td> <div style="position:relative&quo ...
- 字节流和字符流的read方法
字节流和字符流的read方法 public class Test { public void fileOutput() throws Exception { File file = new File( ...
- LeetCode第144场周赛总结
5117.IP地址无效化 首先计算出输入IP地址的长度,然后遍历每一个字符. 如果当前字符为'.',就在它的前后两侧分别加上'['和']'字符. 值得一提的是,C++的String类型提供了以上操作的 ...
- selenium的鼠标事件操作
自动化测试过程中,经常会用到鼠标事件,在selenium的action_chains模块的ActionChains定义了鼠标操作的一些事件,要使用ActionChains类中的方法,首先需要对Acti ...