【HDU - 1069】 Monkey and Banana (基础dp)
Monkey and Banana
直接写中文了
Problem Statement
Input
Output
对于每组测试数据,输出最大高度。格式:Case 第几组数据: maximum height = 最大高度
Sample Input
110 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
Sample Output
Case 1: maximum height = 40Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
题目链接:
https://vjudge.net/problem/HDU-1069
一块砖头有6种方式去摆放(1,2,3)(1,3,2)(2,1,3)(2,3,1)(3,1,2)(3,2,1)
上面的砖头长(l) ,宽(s)必须分别小于下面的
dp[i]为第i个砖头是最下面的那个砖头时候 可以达到的最大高度
AC代码
#include <bits/stdc++.h>
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
#define Maxn 1000
using namespace std;
struct node
{
int l,s,h;//长 宽 高
node(int l,int s,int h):l(l),s(s),h(h) {}
bool operator<(const node &c)const//从小到大排序
{
if(l==c.l)
return s<c.s;
return l<c.l;
} };
vector<node> v;
int dp[Maxn];
int main()
{
int n,k=;
while(cin>>n&&n!=)
{
k++;
v.clear();//清空,初始化
MEM(dp,);
int cnt=;
int a,b,c;
for(int i=; i<n; i++)
{
cin>>a>>b>>c;//依次存入
v.push_back(node(a,b,c));
v.push_back(node(a,c,b));
v.push_back(node(b,a,c));
v.push_back(node(b,c,a));
v.push_back(node(c,b,a));
v.push_back(node(c,a,b));
}
sort(v.begin(),v.end());//排序
int ans=;
for(int i=; i<v.size(); i++)//从最小的那块砖开始
{
dp[i]=v[i].h;//一开始以就这一块砖头,dp[i]=v[i].h
for(int j=i-; j>=; j--)//开始往上找比它小的砖头
{
//第j块砖头的长、宽分别比第i块小,且以第j块砖头为底层的高度+第i块砖的高度 大于 以第i块砖为底层的高度,则更新dp[i]
if(v[j].l<v[i].l&&v[j].s<v[i].s&&dp[j]+v[i].h>dp[i])
dp[i]=dp[j]+v[i].h;
}
if(dp[i]>ans)
ans=dp[i];
}
cout<<"Case "<<k<<": maximum height = "<<ans<<endl;
}
return ;
}
【HDU - 1069】 Monkey and Banana (基础dp)的更多相关文章
- HDU 1069 Monkey and Banana 基础DP
题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...
- 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——最大递减子序列)
题目链接: 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 ...
- HDU 1069 Monkey and Banana(DP 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
随机推荐
- 如何在匿名thread子类中保证线程安全
在做性能测试的过程中,我写了两个虚拟类ThreadLimitTimeCount和ThreadLimitTimesCount做框架,通过对线程的标记来完成超时请求的记录.旧方法如下: @Override ...
- SpringMVC简单使用教程
一.SpringMVC简单入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 <!--conf ...
- 外网主机远程ssh局域网Linux
最近,公司有台配置极高的主机盒子(i7,32G,512G),组长让我装上kali,平时渗透测试时可以用,其余时间归我了,这么高配置的机器,怎么舍得让它吃灰呢 .所以我就去研究了一下,如何远程访问局域网 ...
- 一个低级shell简易学生信息管理系统-新增登陆注册功能
还有bug 不修改了 小声bb一下 这玩意真的要控制版本 随手保存 本来有个超完整的版本 一开心被我rm - f 了 后续还出现了 更多的bug 仔细仔细 源码如下: record=stu.db if ...
- 从零开始ming的多人联机游戏--游戏客户端(1)六边形地图
打算做的小游戏是一个多人联机的策略类游戏,类似于<文明>那种 游戏的玩法并不确定,开这个坑主要是为了入门后端开发,顺便熟悉下游戏开发 这篇文章使用unity,实现了六边形单元地图的创建.后 ...
- CTF--HTTP服务--命令执行(使用集成工具测试)
开门见山 1. 扫描靶机ip,发现PCS 192.168.1.158 2. 用sparta工具对靶机进行信息探测 3. 扫描结果 4. 在浏览器中查看80端口的页面 5. 查看网站信息 6. 暴力破解 ...
- 每天一道Java题[9]
题目 native关键字的作用是什么? 解答 首先,需了解JNI(Java Native Interface),它是连接Java平台与本地C代码的一个API. 其次,用native关键字声明的方法,是 ...
- vue报错Error in v-on handler: "RangeError: Maximum call stack size exceeded"
看下面的报错 错误 看到这个错误一脸懵逼.后面了解到,是因为程序进入了死循环,后面检查了我的代码,原来在这里自己调用自己
- 乌班图14更新软件提示错误:https://mirrors.aliyun.com kubernetes-xenial InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY 6A030B21BA07F4FB
提示如下 获取: https://mirrors.aliyun.com kubernetes-xenial InRelease 忽略 https://mirrors.aliyun.com kubern ...
- python笔记15
今日内容 模块知识 内置模块 time datetime json 其他 内容回顾 & 作业题 重要知识点 构造字典和函数对应关系,避免重复的if else a=1 b=2 ==> a, ...