【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 ...
随机推荐
- RTC时间设置
1.命令行输入date,查看系统时间. 2.命令行输入 date -s "2019-01-21 16:03:00" 修改系统时间. 3.命令行输入 hwclock -w 将修改后的 ...
- Nginx. 用http访问https跨域
用http 访问 https域名, 报跨越问题 解决方法: 在nginx相应服务的转发配置下添加: add_header 'Access-Control-Allow-Origin' 'http://i ...
- MySQL 相关规约(v1.0) (转)
0)前言 a. 基本规约 [强制]表存储引擎必须使用InnoDB(针对主库一般是强制要求的) [强制]表字符集默认使用utf8,必要时候使用utf8mb4(个人踩坑:emoji表情存储问题)•说明:• ...
- 使用静态URL片段 URL路由 精通ASP-NET-MVC-5-弗瑞曼
- 如何理解 HTMLTestRunner 中 test (result)?UnitTest是如何运行的?
我们在用Unittest框架时,生成html格式的报告一般都是用HTMLTestRunner.py这个第三方库,大概使用方法如下: with open(config.report_file, 'wb' ...
- Mybatis基础(二)
Mybatis连接池 Mybatis连接池提供了三种配置方式,配置的位置在SqlMapConfig.xml的dataSource标签中,其type属性就是配置连接池的种类.type的可取值 1.POO ...
- SpringMVC 上传文件 MultipartFile 转为 File
在使用 SpringMVC 上传文件时,接收到的文件格式为 MultipartFile,但是在很多场景下使用都需要File格式的文件,记录下以便日后使用. 以下mFile为MultipartFile文 ...
- 学习记录(Python列表)
列表(List)是Python语言中最通用的序列数据结构之一,列表是一个没有固定长度的,用来表示任意类型对象的位置相关的有序集合.列表中的数据项不需要具有相同的数据类型 列表的基本操作: 1.创建列表 ...
- C++内存管理笔记(一)
C++内存分配的四个层面 : 四个层面的比较: 内存分配与释放的测试: ); //512 bytes free(p1); complex<int>* p2 = new complex& ...
- FFmpeg被声明为已否决的解决方案
参考雷神的最简单的打印Hello World的程序: #include <stdio.h> #include <string.h> extern "C" { ...