题目链接: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. Oracle11g自带的SQL_developer无法打开

    在安装完Oracle Database 11g Release 2数据库,想试一下Oracle自带的SQL DeveloperW工具,在操作系统菜单的所有程序中找到SQL Developer如下所示, ...

  2. PHP的openssl_encrypt方法的JAVA和JS的实现

    这次在JAVA项目中遇到了要使用PHP的openssl_encrypt这个方法来进行加密以下是内容分享: 在PHP中加密内容是: // openssl_encrypt($data, $method, ...

  3. Java代码优化笔记

    指定类.方法的final修饰符 为类指定final修饰符可以让类不可以被继承,为方法指定final修饰符可以让方法不可以被重写.如果指定了一个类为final,则该类所有的方法都是final的.Java ...

  4. Mycat入门配置_读写分离配置

    1.Mycat的分片 两台数据库服务器: 192.168.80.11 192.168.80.4 操作系统版本环境:centos6.5 数据库版本:5.6 mycat版本:1.4 release 数据库 ...

  5. SQL Server 如何添加删除外键、主键,以及更新自增属性

    1.添加删除主键和外键 例如: -----删除主键约束DECLARE @NAME SYSNAMEDECLARE @TB_NAME SYSNAMESET @TB_NAME = 'Date'SELECT ...

  6. HDU3592(差分约束)

    World Exhibition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. 排序算法(1)--Insert Sorting--插入排序[1]--straight insertion sort--直接插入排序

    作者QQ:1095737364    QQ群:123300273     欢迎加入! 1.基本思想 将一个记录插入到已排序好的有序表中,从而得到一个新,记录数增1的有序表.即:先将序列的第1个记录看成 ...

  8. [基础知识]在PeopleSoft中SMTP设置不生效如何查找问题

    在PeopleSoft中如果配置了工作流邮件或者标准页面的通知,都是可以发送出邮件的,这些邮件都是由SMTP服务器发送.SMTP需要在APP服务器和PRCS服务器中配置. 如果无法从PeopleSof ...

  9. 【three.js练习程序】旋转、缩放场景

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. LeetCode 题解之Number Complement

    1.题目描述 2.题目分析 使用 C++的 bitset 库进行操作: 3.代码 int findComplement(int num) { bitset<> b(num); string ...