题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=93

一堆科学家研究猩猩的智商,给他M种长方体,每种N个。

然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉。

现在给你M种长方体,计算,最高能堆多高。

要求位于上面的长方体的长要大于(注意不是大于等于)下面长方体的长,上面长方体的宽大于下面长方体的宽。

解题:

1、一个长方体,可以有6种不同的摆法。长宽排序,就可以只存下来三种,需要的是高的唯一性。

2、将所有长方体按底面积升序排序。

3、第 i 个长方体的最大值 = 前i个(0到i - 1)长方体所能构成的最大高度 + 自己的高度。(升序是为了保证前 i 个长方体底面积一定≤第 i 个,是有可能摆在第i个上面的。)

转移方程:

4、遍历一遍dp数组,得到最大值。

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

class block {
public:
    int length, width, height;
    block() {};
    block(int x, int y, int z) {
        length = x; width = y; height = z;
    }
    //按底面积大小升序排序
    bool operator <(block b) const {
        return length * width < b.width* b.length;
    }
}cube[];
];

bool check(block under, block upper) {
    if (under.length > upper.length && under.width > upper.width) return true;
    return false;
}
int main() {
    ;
    while (cin >> n) {
        )break;
        ; i < n; i++) {
            int l, w, h;
            scanf("%d%d%d", &l, &w, &h);
            //长方体的height,length,width分别作高
            cube[i *  + ] = block(l > w ? l : w, l > w ? w : l, h);
            cube[i *  + ] = block(w > h ? w : h, w > h ? h : w, l);
            cube[i *  + ] = block(h > l ? h : l, l > h ? h : l, w);
        }
        sort(cube, cube + n * );

        dp[] = cube[].height;

        ; i < n * ; i++) {
            ;
            ; j < i; j++) {
                if (cube[i].length > cube[j].length && cube[i].width > cube[j].width) {
                    temp = dp[j] > temp ? dp[j] : temp;//找前i个长方体的最大值
                }
            }
            dp[i] = cube[i].height + temp;
        }

        ;
        ; i < n * ; i++) {
            max = dp[i] > max ? dp[i] : max;
        }
        cout << "Case " << k++ << ": maximum height = " << max << endl;
    }
    ;
}

随手练——ZOJ 1093 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. ZOJ 1093 Monkey and Banana (LIS)解题报告

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

  3. HDU——Monkey and Banana 动态规划

                                                                       Monkey and Banana Time Limit:2000 ...

  4. Monkey and Banana 题解(动态规划)

    Monkey and Banana 简单的动态规划 1.注: 本人第一篇博客,有啥不足还请多多包涵,有好的建议请指出.你以为有人读你博客,还给你提意见. 2.原题 Background: A grou ...

  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(HDU 1069 动态规划)

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

  7. HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)

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

  8. hdu1069Monkey 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 dp 题解

    HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...

随机推荐

  1. 【Linux】rpm常用命令及rpm参数介绍

    RPM是RedhatPackageManager的缩写,是由RedHat公司开发的软件包安装和管理程序,同Windows平台上的Uninstaller比较类似.使用RPM,用户可以自行安装和管理Lin ...

  2. 【C#数据结构系列】栈和队列

    一:栈 栈和队列也是线性结构,线性表.栈和队列这三种数据结构的数据元素以及数据元素间的逻辑关系完全相同,差别是线性表的操作不受限制,而栈和队列的操作受到限制.栈的操作只能在表的一端进行,队列的插入操作 ...

  3. python基础训练题1-列表操作

    1,在列表末尾添加一个值 >>> l = [ 10, 20 ] >>> l [10, 20] >>> l.append( 'ghostwu' ) ...

  4. Bootstrap4响应式布局之栅格系统

    前面说了Bootstrap4的下载和简单使用,现在我们接着往下学习,Bootstrap4的响应式布局主要依靠栅格系统来实现的.面老K先来讲解一下Bootstrap4的栅格系统,让你能够更快的了解Boo ...

  5. 从零开始学习html(十二)CSS布局模型——上

    一.css布局模型 清楚了CSS 盒模型的基本概念. 盒模型类型, 我们就可以深入探讨网页布局的基本模型了. 布局模型与盒模型一样都是 CSS 最基本. 最核心的概念. 但布局模型是建立在盒模型基础之 ...

  6. chrome-Firefox-IE浏览器兼容总结

    作为一名WEB前端程序员,相信每个人对浏览器的兼容都"情有独钟",下面就一些常用的浏览器的兼容列举一二. 一.块级元素(block)一般不转化为inline-block,其实是因为 ...

  7. JS--我发现,原来你是这样的JS(一)(初识,历史)

    一.前言: 前段时间看红宝书(JavaScript高级程序设计),但没有计划的去看,也没有做详细的笔记,读了之后有点空虚,感觉不对劲啊,学的东西很难记住,印象不深啊,有种挫败感. 作前端的js都学不好 ...

  8. 葡萄城报表 SP2 新特性(1)— 单元格智能合并

    中国式复杂报表的布局,因为数据的动态性和结构性,导致其布局往往是无规律,且在设计时无法预测的,如单元格合并,通常不仅希望在每一列的数据展现中,能够根据需要自动将相同的单元格合并,且每个单元格之间该属性 ...

  9. IDEA报错:Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. ('crmWatcherService'错误)

    单表插入项目,插入前正常,插入后运行webapplication报错: run: debug: 于webapplication报错: Injection of autowired dependenci ...

  10. Android手机上,利用bat脚本模拟用户操作

    ………… 那么你就可以来看看这篇帖子了. 言归正传 利用bat脚本模拟用户操作,需要用到两点: ①就是adb命令了,adb命令可以用来模拟用户在手机上的操作 ②bat语言,就是批处理语言,主要用来进行 ...