题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069

简单记录一下

思路:把长方体的各种摆法都存到数组里面,然后按照长宽排序,再dp即可

转移方程 dp[i]=max(dp[i],dp[t]+a[i].z)  //dp里存的是高度,a[i].z是第i个的高度
 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#define ll long long
#define pi 3.1415927
#define inf 0x3f3f3f3f
using namespace std;
struct node {
int x,y,z;
}a[];
bool cmp (node x, node y)
{
if (x.x==y.x)
return x.y<y.y;
return x.x<y.x;
}
int dp[];
int main ()
{
int n,m,i,t,sum,j=,k;
while(cin>>n)
{
j++;
if(n==)
break;
k=;
for(i=;i<n;++i)
{
int x,y,z;
cin>>x>>y>>z;
if(x==y==z)
a[k].x=x, a[k].y=y, a[k++].z=z;
else if (x==y)
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=x, a[k].y=z, a[k++].z=y,
a[k].x=z, a[k].y=x, a[k++].z=y;
else if (x==z)
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=x, a[k].y=z, a[k++].z=y,
a[k].x=y, a[k].y=x, a[k++].z=z;
else if (y==z)
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=z, a[k].y=y, a[k++].z=x,
a[k].x=y, a[k].y=x, a[k++].z=z;
else
a[k].x=x, a[k].y=y, a[k++].z=z,
a[k].x=x, a[k].y=z, a[k++].z=y,
a[k].x=y, a[k].y=x, a[k++].z=z,
a[k].x=y, a[k].y=z, a[k++].z=x,
a[k].x=z, a[k].y=y, a[k++].z=x,
a[k].x=z, a[k].y=x, a[k++].z=y;
}
sort(a,a+k,cmp);
for(i=;i<k;++i)
dp[i]=a[i].z;
int maxs=;
for(i=;i<k;++i)
for(t=;t<i;++t)
{
if(a[i].x>a[t].x &&a[i].y>a[t].y){
dp[i]=max(dp[i],dp[t]+a[i].z);
maxs=max(maxs,dp[i]);
}
}
cout<<"Case "<<j<<": maximum height = "<<maxs<<endl;
} return ;
}

HDU 1069 Monkey and Banana (动态规划)的更多相关文章

  1. 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 ...

  2. HDU 1069 Monkey and Banana dp 题解

    HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...

  3. HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...

  4. HDU 1069 Monkey and Banana(动态规划)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

  5. HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  6. HDU 1069 Monkey and Banana(二维偏序LIS的应用)

    ---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  7. HDU 1069 Monkey and Banana (DP)

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 1069—— Monkey and Banana——————【dp】

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. hdu 1069 Monkey and Banana

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  10. HDU 1069 Monkey and Banana(DP 长方体堆放问题)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

随机推荐

  1. 1.springboot+ActiveMQ

    1.项目结构如下 pom.xml文件如下 <dependencies> <dependency> <groupId>junit</groupId> &l ...

  2. 不同JDK版本之间的intern()方法的区别-JDK6 VS JDK6+

    String s = new Stirng(“a”); s.intern(); JDK6:当调用intern()方法时,如果字符串常量池先前已创建出该字符串对象,则返回池中的该字符串的引用.否则,将此 ...

  3. 2018自己的JavaScript开发指南

    这是一个备忘清单,可以让你在不用做太多选择的情况下快速学习.我会列出一些工具来满足大部分场景下的前端开发.当你看完这篇文章,你会有足够的自信来调整你的技术栈. ☉概要 我会将地图划分为你需要解决的问题 ...

  4. Activiti学习笔记4 — 流程实例化

    1.创建流程引擎对象 private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); 2.启动流程 流程 ...

  5. 《构建之法》CH5~6读书笔记 PB16110698 第九周(~5.15)

    这段时间我阅读了<构建之法>的大部分章节,包括个人技能.软件测试.用户体验和需求分析等相关内容.之前的个人作业和结对作业结束后,我们的工作重心终于转向了团队项目,作为团队中前端组的组长,我 ...

  6. Window sevice +OWIN+webapi

    webapi正常都托管在iis上,这里引入owin,将其托管在window服务上. 第一步:创建一个服务,这里就不多描述. 第二步:引入OWIN 2.1引入bll 2.2加入api路由配置 publi ...

  7. jupyter中使用graphviz

    参考: https://www.cnblogs.com/zhanjiahui/p/11335038.html https://blog.csdn.net/linxid/article/details/ ...

  8. 数据库MySQL--基础查询

    1.查询字段 查询表某字段:select 字段名 from 表名: 查询表内所有字段:select * from 表名: (当字段和关键字重名是用( ` )着重号区分 ) 2.查询常量值 select ...

  9. poj1363 Rails Central Europe 1997

    P.S.: 输出换行 三个方法 1.直接按照要求做 根据给的数,需要push,pop哪些数据,具有唯一性 数最多进栈一次,出栈一次 O(n) Source Code Problem: User: co ...

  10. 推荐一个Java设计模式写的很好的博客

    博客地址:https://quanke.gitbooks.io/design-pattern-java/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E8%AE%BE%E8 ...