链接: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. 今日份Java

    package util; import java.sql.*; public class DBUtil { static String url = "jdbc:mysql://localh ...

  2. 打印机打印pdf文件特别慢怎么解决

    PDF等文件中都包含了一些或者很多光栅化数据(图片.嵌入的字体等).这些文件在打印时,打印机驱动程序都会在系统中生成大量EMF文件(增强型变换文件),小到1MB,大到500MB,过大的EMF临时文件会 ...

  3. jrtp 使用

    jrtplib-3.11.1 使用jthread-1.3.3 # cmake 下载https://cmake.org/download/ 使用地址https://github.com/j0r1/JRT ...

  4. web框架的基础原理

    http协议 HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本 ...

  5. PWA - Manifest

    manifest 在一个JSON文本文件中提供有关应用程序的信息(如名称,作者,图标和描述) manifest 的目的是将Web应用程序安装到设备的主屏幕 部署一个 manifest <link ...

  6. 小希的迷宫 HDU - 1272

    #include<iostream> #include<algorithm> #include<cstring> using namespace std; cons ...

  7. React Hooks 笔记1

    useState const [state, setSate] = useState(initialState) 特征: setState 标识稳定,组件重新渲染时不会变化,useState 返回的第 ...

  8. JavaScript仿计算器案例源代码

    效果图 index.html <!DOCTYPE html> <html> <head> <title></title> <link ...

  9. fastadmin选择下拉框

    fastadmin中要做下拉框的效果如下: 数据库中数据: 在对应model中添加一个方法: 控制器中添加一行: 在目录lang/zh-cn中找到你控制器名称所对应的文件添加配置: 在add.html ...

  10. Mysql中FIND_IN_SET()和IN区别简析

    来源:http://www.jb51.net/article/125744.htm 测试SQL: CREATE TABLE `test` ( `id` int(8) NOT NULL auto_inc ...