题目链接:https://cn.vjudge.net/problem/HDU-1069

题意

给出n种箱子的长宽高

现要搭出最高的箱子塔,使每个箱子的长宽严格小于底下的箱子的长宽,每种箱子数量不限

问最高可以搭出多高

思路

有向无环图(DAG)上的动规

想象有一个图,每个节点表示一种箱子,每个边代表可以落在一块的关系

递归的找max即可

$ dp(i)=max(dp(j)+h(i) | (i, j) \in E) $

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Box{
int x, y, z;
Box(int x=0, int y=0, int z=0):
x(x),y(y),z(z) {}
}box[200];
int n, data[200];
int dp(int idx){
if (data[idx]!=-1) return data[idx];
data[idx]=box[idx].z;
for (int i=0; i<n; i++){
if (i==idx || box[i].x>=box[idx].x || box[i].y>=box[idx].y) continue;
data[idx]=max(data[idx], dp(i)+box[idx].z);
}return data[idx];
} int main(void){
int cnt=0;
while (scanf("%d", &n)==1 && n){
memset(data, -1, sizeof(data));
for (int i=0, x, y, z; i<n; i++){
scanf("%d%d%d", &x, &y, &z);
box[6*i+0]=Box(x, y, z); box[6*i+1]=Box(x, z, y);
box[6*i+2]=Box(y, z, x); box[6*i+3]=Box(y, x, z);
box[6*i+4]=Box(z, x, y); box[6*i+5]=Box(z, y, x);
}n*=6; int max;
for (int i=0; i<n; i++)
if (max<dp(i) || i==0) max=dp(i);
printf("Case %d: maximum height = %d\n", ++cnt, max);
} return 0;
}
Memory Length Lang Submitted
1512kB 1041 G++ 2018-02-16 03:34:42

HDU-1069 Monkey and Banana DAG上的动态规划的更多相关文章

  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——————【dp】

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

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

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

  6. HDU 1069 Monkey and Banana (DP)

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

  7. HDU 1069 Monkey and Banana 基础DP

    题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. ...

  8. hdu 1069 Monkey and Banana

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

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

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

随机推荐

  1. Synergy 共享键盘和鼠标

    直接安装Synergy 不行的话加配置文件 ➜ ~ cat synergy.conf section: screens lab712-PC: ckboss-HP: end section: links ...

  2. JavaScript中Number常用属性和方法

    title: JavaScript中Number常用属性和方法 toc: false date: 2018-10-13 12:31:42 Number.MAX_VALUE--1.79769313486 ...

  3. cookie、sessionStorage和localStorage

    title: cookie.sessionStorage和localStorage toc: false date: 2018-09-25 16:49:57 cookie 由于HTTP协议是无状态的, ...

  4. MySQL用户添加和分配权限

    mysql数据库insertdelete服务器file mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口 ...

  5. centos下nginx配置

    转自  http://www.linuxidc.com/Linux/2016-09/134907.htm 安装所需环境 Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Wi ...

  6. windows2008搭建ftp服务器

    控制面板 操作—〉添加角色 (web,文件服务) windows 搜索中: 添加ftp站点: 计算机---管理 –服务器管理  --- 添加一个用户 ,密码. 防护墙高级设置中添加 出入站规则 允许2 ...

  7. vue反向代理解决跨域

    问题描述 在项目开发的时候,接口联调的时候一般都是同域名下,且不存在跨域的情况下进行接口联调,但是当我们现在使用vue-cli进行项目打包的时候,我们在本地启动服务器后,比如本地开发服务下是 http ...

  8. NOIp模拟赛三十四(yxq供题)

    毒瘤yxq! 毒瘤yxq! 毒瘤yxq! 据yxq自己说,林导让他出题的时候要求是“代码量少”,“思维难度高”,“不涉及太复杂的算法”,而且“最好要让myh有一题做不出来”(狙击myh).于是今天的题 ...

  9. UVA-1602 Lattice Animals 搜索问题(打表+set)

    题目链接 https://vjudge.net/problem/UVA-1602 紫书的一道例题,跟之前的很多题目有很多不同. 本题不像是一般的dfs或bfs这样的搜索套路,而是另一种枚举思路. 题意 ...

  10. luogu P1630 求和(枚举暴力)

    题意 题解 可以发现当a=10001时, 和1是等价的. 所以这题就水了. #include<iostream> #include<cstring> #include<c ...