【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 ...
随机推荐
- 使用ajax向后台发送请求跳转页面无效的原因
Ajax只是利用脚本访问对应url获取数据而已,不能做除了获取返回数据以外的其它动作了.所以浏览器端是不会发起重定向的. 1)正常的http url请求,只有浏览器和服务器两个参与者.浏览器端发起一个 ...
- leetcode 最大水池
leetcode 11题 水池最大容积 题目描述 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 ( ...
- Ubuntu18.04 安装配置mongodb
一.安装 # 1. 更新 sudo apt-get update # 2. 安装 sudo apt-get install -y mongodb # 3. 查看是否安装成功 # a. 服务状态 sud ...
- MTV
M:模型 models.py T:模板 html C:控制 urls.py 和 views.py 与MVC类似
- 【新书推荐】《ASP.NET Core微服务实战:在云环境中开发、测试和部署跨平台服务》 带你走近微服务开发
<ASP.NET Core 微服务实战>译者序:https://blog.jijiechen.com/post/aspnetcore-microservices-preface-by-tr ...
- 【javaScript】获取某年某月的的最后一天(即当月天数) 妙用
javaScript里 面的new Date("xxxx/xx/xx")这个日期的构造方法有一个妙处,当你传入的是"xxxx/xx/0"(0号)的话,得到的日期 ...
- linux操作系统下调试python代码方法
一.python有调试工具pdb,可以用来进行代码调试. pdb的常用命令说明: l #查看运行到哪行代码 n #单步运行,跳过函数 s #单步运行,可进入函数 p 变量 #查看变量值 b 行号 #断 ...
- Mixing .NET
- SpringBoot配置国际化
1).国际化 1).编写国际化配置文件: 2).使用ResourceBundleMessageSource管理国际化资源文件 3).在页面使用fmt:message取出国际化内容 步骤: 1).编写国 ...
- jdk for centos7
https://www.cnblogs.com/chy123/p/6750351.html