HDU 1069 Monkey and Banana dp 题解

HDU 1069 Monkey and Banana 题解

纵有疾风起

题目大意

一堆科学家研究猩猩的智商,给他M种长方体,每种N个。然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉。

现在给你M种长方体,计算,最高能堆多高。要求位于上面的长方体的长要大于(注意不是大于等于)下面长方体的长,上面长方体的宽大于下面长方体的宽。

输入输出

开始一个数n,表示有多少种木块,木块的数量无限,然后接下来的n行,每行3个数,是木块的长宽高三个参量

输出使用这些在满足条件的情况下能够摆放的最大高度

解题思路

首先,我们严格令长>宽,可以想到一种木块有3种摆放方式,长、宽、高分别在下面。

对于摆放种类,我们可以使用dp动态规划来进行,看了其他博主写的博客,这个题和求最长递增子序列差不多(反过来想的,就是把塔给倒过来进行构造)。

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;
const int N=207;

struct note
{
    int l,w,h;
}cd[N];

int dp[N];

bool cmp( note cod1,note cod2 ) //按照长宽进行排序,大的在前
{
    if( cod1.l==cod2.l ) //长相同,宽 大的在前
        return cod1.w > cod2.w;
    return cod1.l > cod2.l;
}

int main()
{
    int n,len,t_num=1;
    int z1,z2,z3;
    while( scanf("%d", &n) && n )
    {
        len=0;
        for(int i=0; i<n; i++)
        {
            cin>>z1>>z2>>z3;
            cd[len].h=z1; cd[len].l=z2>z3?z2:z3; cd[len++].w=z2>z3?z3:z2;
            cd[len].h=z2; cd[len].l=z1>z3?z1:z3; cd[len++].w=z1>z3?z3:z1;
            cd[len].h=z3; cd[len].l=z1>z2?z1:z2; cd[len++].w=z1>z2?z2:z1;
        }
        sort(cd,cd+len,cmp);
        dp[0]=cd[0].h;
        int max_h, ans=0;
        for(int i=1; i<len; i++)
        {
            max_h=0;
            for(int j=0; j<i; j++ )
            {
                if( cd[j].l>cd[i].l && cd[j].w>cd[i].w )
                    max_h = max_h>dp[j] ? max_h : dp[j];
            }
            dp[i]=cd[i].h+max_h;
            ans=max(ans, dp[i]);
        }
        cout<<"Case "<<t_num++<<": maximum height = "<<ans<<endl;
    }
    return 0;
}

原文地址:https://www.cnblogs.com/alking1001/p/11230571.html

时间: 2024-08-01 10:42:21

HDU 1069 Monkey and Banana dp 题解的相关文章

HDU 1069 Monkey and Banana(DP 长方体堆放问题)

Monkey and Banana Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever

HDU 1069 Monkey and Banana DP LIS变形题

http://acm.hdu.edu.cn/showproblem.php?pid=1069 意思就是给定n种箱子,每种箱子都有无限个,每种箱子都是有三个参数(x, y, z)来确定. 你可以选任意两个参数作为长和宽,第三个是高. 然后要求把箱子搭起来,使得高度最高. 能搭的前提是下面那个箱子的长和宽都 > 上面那个箱子的. 思路: 因为同一个箱子可以产生6中不同的箱子,而每种最多选一个,因为相同的箱子最多只能搭起来一个. 那么可以把所有箱子都弄出来,排序,就是LIS的题目了. dp[i]表示以

hdu 1069 Monkey and Banana (dp)

//把给定的长方体(不限)叠加在一起,叠加的条件是,上面一个长方体的长和宽都比下面长方体的长 /* 分析:因为每块积木最多有3个不同的底面和高度,因此先把每块积木看成三种不同的积木, 每种积木只有一个底面和一个高度.n中类型的积木转化为3*n个不同的积木的叠加, 对这3 * n个积木的长边从大到小排序:接下来的问题就是找到一个递减的子序列, 使得子序列的高度和最大即可. 数组dp:dp[i]表示是以第i块积木为顶的塔的最大高度 因此可得状态转移方程:dp[i] = max(dp[i],dp[j]

HDU 1069 monkey an banana DP LIS

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64uDescription 一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子足够聪明,它应当能够通过合理的放置一些砖块建立一个塔,并爬上去吃他们最喜欢的香蕉. 研究人员有n种类型的砖块,每种类型的砖块都有无限个.第i块砖块的长宽高分别用xi,yi,zi来表示. 同时,由于砖块是可以旋转

[2016-03-30][HDU][1069][Monkey and Banana]

时间:2016-03-27 15:19:40 星期日 题目编号:[2016-03-30][HDU][1069][Monkey and Banana] 题目大意:给定n种积木无限个,问这些积木最大能叠多高,上面的积木长宽必须严格小于下面的积木 分析: dp[i]表示第i个积木在顶部时候的最大高度,那么dp[i] = max(dp[i],dp[j] + h[i]);?ji能放在j上面?ji能放在j上面 初始条件就是长宽最大的高度是它自己, #include <algorithm> #include

HDU 1069 Monkey and Banana (动规)

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7248    Accepted Submission(s): 3730 Problem Description A group of researchers are designing an experiment to test the IQ of a

HDU 1069 Monkey and Banana 基础DP

题目链接:Monkey and Banana 大意:给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. 简单的DP,依然有很多地发给当时没想到.比如优先级,比如这么简单粗暴的选择. 1 /* 2 大意是.给出n种箱子的长宽高.每种不限个数.可以堆叠.询问可以达到的最高高度是多少. 3 要求两个箱子堆叠的时候叠加的面.上面的面的两维长度都严格小于下面的. 4 5 样例: 6 10 20 30 7 10

DP [HDU 1069] Monkey and Banana

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7854    Accepted Submission(s): 4051 Problem Description A group of researchers are designing an experiment to test the IQ of a

hdu 1069 Monkey and Banana (结构体排序,也属于简单的dp)

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7770    Accepted Submission(s): 4003 Problem Description A group of researchers are designing an experiment to test the IQ of a