题目链接: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. (八)统一配置中心-Config

    对于配置的重要性,我想我不用进行任何强调,大家都可以明白其重要性.在普通单体应用,我们常使用配置文件(application(*).properties(yml))管理应用的所有配置.这些配置文件在单 ...

  2. Andoid CustomCircleProgress 半圆

    package com.play.playgame.view; import android.content.Context; import android.graphics.Canvas; impo ...

  3. TLCL

    参考阅读:http://billie66.github.io/TLCL/book/chap04.html 绝对路径 An absolute pathname begins with the root ...

  4. ActiveMQ学习笔记(18)----Message高级特性(二)

    1. Blob Message 有些时候,我们需要传递Blob(Binary Large Objects)消息,在5.14之前,(5.12和5.13需要在jetty.xml中手动开启)可以按照如下的方 ...

  5. h5 input失去焦点软键盘把页面顶起

    var broswer=localStorage.getItem('temp') //浏览器环境 var u = navigator.userAgent var isiOS = !!u.match(/ ...

  6. git远程仓库变更

    查看自己的远程仓库 git remote -v 远程仓库变更 git remote remove origin //移出现有的远程仓库的地址 git remote add origin http:// ...

  7. 使用windowbuilder的时候更方便——设置默认把控件生成为成员变量而不是局部变量

    找了一大圈,最后还是上Google才找到这个方法的.以前改过了,重新设置工作目录之后设置都丢失了,却找不到改的办法,这次长个记性,记在自己博客里. 设置成成员属性的好处是随后使用这些控件的时候方便.

  8. Hadoop2.x 关于日志文件位置

    查看日志是发现Hadoop问题和解决Hadoop问题的第一步. 开始我不知道该去哪找日志,后来我发现在我启动节点的时候,有打印信息以及明确告诉了日志写在哪. [root@master hadoop]# ...

  9. 最强最全干货分享:Android开发书籍、教程、工具等

    最全干货分享,本文收集整理了Android开发所需的书籍.教程.工具.资讯和周刊各种资源,它们能让你在Android开发之旅的各个阶段都受益. 入门<Learning Android(中文版)& ...

  10. Java数据库訪问小结

    </pre>1.JDBC訪问方法</p><p></p><p>DBHelper类訪问数据库.Dao类写数据訪问,View类进行应用,初学实例图 ...