题目链接: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. Neo4j模糊查询及分页查询

    Neo4j模糊查询:采用正则方式: MATCH (n:House) where n.Name =~ '李.*' RETURN n 分页: 使用skip 及 limit MATCH (n:House) ...

  2. Cookie自动管理

    如果想要对 cookies 干点什么就需要 HTTP Cookie 管理器了. 啥是 cookies 呢.储存在用户本地终端上的数据通常情况下,当用户结束浏览器会话 时,系统将终止所有的 Cookie ...

  3. Word 多级节标题设置和图表章节号自动生成

    写文章的时候,正文.图表.节标题,通过“样式”可以进行统一设置,这里我记录了几点小技巧: 1.多级标题如何设置 假设我要设置三级标题,下面以图的形式记录方式: 设置完之后,应用即可. 章节设定之后,可 ...

  4. pandas中series求交集

    在进行数据探索的时候会遇到求交集的情况,比如说:优惠卷预测的时候,有多张表,表1有用户id,表2也有用户id,但是不能确定表1的用户有多少出现在表2当中. un_id1,un_id2 为两个 Seri ...

  5. 2019-6-23-win10-uwp-开发-CSDN-访问量统计-源代码

    title author date CreateTime categories win10 uwp 开发 CSDN 访问量统计 源代码 lindexi 2019-6-23 11:2:1 +0800 2 ...

  6. 在Linux(centos)下,安装Apache和PHP环境

    1001  ll /opt/lampp/modules/ 1002  history | grep httpd 1003  vim /etc/httpd/conf/httpd.conf 1004  v ...

  7. Leetcode207. Course Schedule课程表

    现在你总共有 n 门课需要选,记为 0 到 n-1. 在选修某些课程之前需要一些先修课程. 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1] 给定课程总量以及它 ...

  8. The linux command 之权限

    一.修改权限 只有文件主或者超级用户才可以修改文件或者目录的权限. 符号表示法分为三种: Who the change will affect Which operation will be perf ...

  9. code+第四次网络赛div2

    T1 组合数问题: 用k个不完全相同的组合数表示一个数n. 用k-1个1和一个n-k+1表示即可. #include<cstdio> using namespace std; int x, ...

  10. 【JZOJ6288】旋转子段

    description analysis 可以先用前缀和把原串不调整的方案数先求出来 对于一种翻转,肯定是把\([i..a[i]]\)或\([a[i]..i]\)这段区间翻转 也可以看做是以\({i+ ...