【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 Playbooks常用模块
File模块 在目标主机创建文件或目录,并赋予其系统权限 - name: create a file file:'path=/oot/foo.txt state=touch mode=0755 own ...
- Java.前端模板.Thymleaf
1. Input 日期格式化 <input id="renewalDate" name="renewalDate" th:value="${#d ...
- Jenkins自动执行python脚本输出测试报告
前言 在用python做自动化测试时,我们写好代码,然后需要执行才能得到测试报告,这时我们可以通过 Jenkins 来进一步完成自动化工作. 借助Jenkins,我们可以结合 Git/SVN 自动拉取 ...
- 每天玩转3分钟 MyBatis-Plus - 5. 高级查询(三)(条件构造器)
每天玩转3分钟 MyBatis-Plus - 1. 配置环境 每天玩转3分钟 MyBatis-Plus - 2. 普通查询 每天玩转3分钟 MyBatis-Plus - 3. 高级查询(一) 每天玩转 ...
- 使用Jenkins持续集成
本篇文章主要说明的是如何使用Jenkins持续集成自己的代码. 1.Jenkins的安装与配置 使用Jenkins之前需要安装和配置Jenkins,具体安装和配置方法参照这个博客:http://www ...
- REST 风格架构
------------------------------ 时间不多了, 抓紧做一些有意义的事情 REST 风格架构 1. 他是面向资源进行开发的 2. 他是基于HTTP 协议进行开发 ...
- SpringCloud与微服务Ⅱ --- 微服务概述
一.什么是微服务 1) Martin Fowler论文对微服务的阐述(中文版) 2) 对单一应用进行拆分 3) 每一个独立的应用都有一个独立的进程 4) 拥有自己独立的数据库 5) 微服务化的核心就是 ...
- CUDA学习(三)之使用GPU进行两个数组相加
传入两个数组,在GPU中将两个数组对应索引位置相加 #include "cuda_runtime.h" #include "device_launch_parameter ...
- DOCKER 学习笔记4 认识DockerCompose 多容器编排
前言 通过上一节的学习,学会了如何在Linux 环境下搭建Docker并且部署Springboot 项目,并且成功的跑了起来,当然,在生产环境中,不只是需要一个后端的Web 项目,还需要比如 Ngin ...
- python day01练习和作业
习题:1.简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型编译型语言:优点:执行速度快 缺点:维护成本高,跨平台性差解释型语言:优点:维护成本低,跨平台性好 缺点:执 ...