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

题意:给定n种类型的长方体,每个类型长方体无数个,要求长方体叠放在一起,且上面的长方体接触面积要小于下面,长宽也小于下面的长方体,求最高能叠放多高?

思路:首先每个长方体有三种情况可以作为底部,那么一共是3*n种类型的长方体,首先按长宽的大小排序,然后dp。dp[i]表示以第i块长方体为顶的最大高度,那么转移方程就是dp[i] = max(dp[i],dp[j] +  g[i]. h),形似一个LIS的dp,枚举 j 即可

AC代码:

 #include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<unordered_map>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = ;
int dp[maxn];
struct node{
int x,y,z;
}g[maxn];//设z为高度 ,x,y分别为长和宽
bool cmp(node a,node b){
if(a.x == b.x ) return a.y > b.y ;
return a.x > b.x ;
}
int m,n;
int main(){
int cnt = ;
while(scanf("%d",&n)){
if(n == ) break;
memset(dp,,sizeof(dp));
for(int i = ;i<=*n;i+=){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
g[i].x = x<y? x:y;
g[i].y = y>x? y:x;
g[i].z = z;
g[i+].x = x<z? x:z;
g[i+].y = z>x? z:x;
g[i+].z = y;
g[i+].x = y<z? y:z;
g[i+].y = z>y? z:y;
g[i+].z = x;
}
sort(g+,g++*n,cmp);
for(int i = ;i<=*n;i++) dp[i] = g[i].z ;
int ans = dp[];
for(int i = ;i<=*n;i++){
for(int j = ;j<i;j++){
if(g[j].x > g[i].x && g[j].y > g[i].y ){
dp[i] = max(dp[i],dp[j]+g[i].z );//形似一个LIS的dp
ans = max(ans,dp[i]);
}
}
}
printf("Case %d: maximum height = %d\n",cnt,ans);
cnt++;
}
return ;
}

HDU1069 Monkey and Banana(dp)的更多相关文章

  1. HDU 1069:Monkey and Banana(DP)

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

  2. HDU 1069 Monkey and Banana (dp)

    题目链接 Problem Description A group of researchers are designing an experiment to test the IQ of a monk ...

  3. HDU 1069 Monkey and Banana ——(DP)

    简单DP. 题意:给出若干种长方体,如果摆放时一个长方体的长和宽小于另一个的长宽,那么它可以放在另一个的上面,问最高能放多少高度.每种长方体的个数都是无限的. 做法:因为每种个数都是无限,那么每种按照 ...

  4. ZOJ 1093 Monkey and Banana (LIS)解题报告

    ZOJ  1093   Monkey and Banana  (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

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

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

  6. Monkey and Banana(dp,求最长的下降子序列)

    A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a bana ...

  7. HDU 1069 Monkey and Banana(DP——最大递减子序列)

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 题意描述: 给n块砖,给出其长,宽和高 问将这n块砖,怎样叠放使得满足以下条件使得 ...

  8. 随手练——ZOJ 1093 Monkey and Banana(动态规划)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=93 一堆科学家研究猩猩的智商,给他M种长方体,每种N个. 然后,将一个 ...

  9. hdoj1069 Monkey and Banana(DP--LIS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 思路: 由题意,显然一种block可能有6种形式,且一种形式最多使用一次,因此最多有30×6=1 ...

随机推荐

  1. C++文件读写demo

    一.常用文件打开方式 二.读写文件步骤(文本文件) 1.写文件步骤 1)#include <fstream> //包含头文件 2)ofstream ofs; //创建流对象 3)ofs.o ...

  2. 吴裕雄--天生自然 python数据分析:医疗费数据分析

    import numpy as np import pandas as pd import os import matplotlib.pyplot as pl import seaborn as sn ...

  3. H5---禁止长按

    以上行为可以总结成这几个(每个手机以及浏览器的表现形式不一样):长按图片保存.长按选择文字.长按链接/手机号/邮箱时呼出菜单. 想要禁止这些浏览器的默认行为,可以使用以下CSS: // 禁止长按图片保 ...

  4. MySQL manager or server PID file could not be found!

    [root@centos var]# service mysqld stop MySQL manager or server PID file could not be found!       [F ...

  5. 使用SSM 或者 springboot +mybatis时,对数据库的认证信息(用户名,密码)进行加密。

    通常情况下,为了提高安全性,我们需要对数据库的认证信息进行加密操作,然后在启动项目的时候,会自动解密来核对信息是否正确.下面介绍在SSM和springboot项目中分别是怎样实现的. 无论是使用SSM ...

  6. function_use

    # 函数说明文档,help(len) def sum1(a, b): """ 求和函数sum1 :param a: 参数1 :param b: 参数2 :return: ...

  7. gulp常用插件之gulp-rev使用

    更多gulp常用插件使用请访问:gulp常用插件汇总 gulp-rev这是一款为静态文件随机添加一串hash值, 解决cdn缓存问题, a.css --> a-d2f3f35d3.css.根据静 ...

  8. 台大郭彦甫MATLAB教学-个人笔记(一)

    命令和一些特殊的变量 who:查看有哪些变量1. whos:可以查看变量的大小.字节和类型等资料. clear:如果单独使用则是清空所有命令,若后面跟着一个变量名称则为删除此变量. clc:清空命令行 ...

  9. [CF1303A] Erasing Zeroes

    Solution 找到边界然后循环扫一遍数个数即可 #include <bits/stdc++.h> using namespace std; int n; const int N = 1 ...

  10. PHP错误日志文件Warning:PHP Startup: Unable to load dynamic library...

    由于我的环境是通过源码编译安装的,安装的时候配置信息和一些其他扩展没安装或设置好: php.err文件一直有这些提示,虽然不影响服务启动,但是看着心好累啊,决定要消灭他们. 问题描述: 出现原因: 上 ...