【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 ...
随机推荐
- Ansible配合Virtualenv安装配置
Ansible的两种安装模式(Centos7) 1.Yum包管理安装 #yum -y install ansible 2.Git源代码安装[推荐] git clone https://github.c ...
- kaggle预测房价的代码步骤
# -*- coding: utf-8 -*- """ Created on Sat Oct 20 14:03:05 2018 @author: 12958 " ...
- GitHub高级搜索指南
还在为自学时找不到适合练手的项目而苦恼? 还在好奇别人是如何在GitHub众多项目中找到高质量代码的? 真的是因为他们独具慧眼吗? 不,其实他们只是掌握了正确的搜索方法. 下面介绍几种常用的GitHu ...
- Spring-cloud微服务实战【六】:接口服务feign
在上一篇文章中,我们使用了ribbon进行负载均衡,但是仔细思考一下,我们的请求封装和调用以及结果的返回都是我们自己编码完成的,如果需要调用的接口很多,那么无疑开发量是比较大的,那有没有比较好的方式呢 ...
- [洛谷P4097] [HEOI2013] Segment
Description 要求在平面直角坐标系下维护两个操作: 1.在平面上加入一条线段.记第 \(i\) 条被插入的线段的标号为 \(i\) 2.给定一个数 \(k\) ,询问与直线 \(x = k\ ...
- 解决浮点运算精度不准确,BigDecimal 加减乘除
package com.kflh.boxApi.utils.util; import java.math.BigDecimal; /** * @program: BoxApi * @descripti ...
- 20200102模拟赛 问题A 排列
先说句新年好哈哈哈 今年又是颓废的一年呢... (开始就满满负能量真好) 分析: 真是有趣的数学递推找规律问题呢... 考场上没想出来,然后n2^n的状压也想不到 索性20*20直接打表2333... ...
- CF990G
题意 https://codeforces.com/contest/990/problem/G 思考 在200000以内,因数个数最多的数位166320,共有160个因数.可以知道,从一个节点向下走最 ...
- ThreeJS 物理材质shader源码分析(像素着色器)
再此之前推荐一款GLTF物理材质在线编辑器https://tinygltf.xyz/ 像素着色器(meshphysical_frag.glsl) #define PHYSICAL uniform ve ...
- AI初探
看东西应该记笔记,不然如过眼云烟,如只逛商场,不买东西,不留下带走什么,就是浪费时间,没有收获,仅此开始,定期梳理看过的东西. 人工智能的目的是什么呢? 答:让机器表现得更像人类,甚至在某些技能上超越 ...