Monkey and Banana HDU - 1069 (贪心+dp)

FMCW雷达基本原理(通俗易懂)篇2 FMCW雷达(Frequency Modulated Continuous Wave Radar)是一种使用频率调制连续波的雷达系统。它使用一个发射器发射一个连续波,但是这个连续波的频率会在一定的范围内不断变化。当这个连续波遇到一个目标物体并被反射回来时,接收器会检测到这个反射波的频率变化,并计算出目标物体的距离和速度等信息。FMCW雷达的原理可以理解为:1.发射器发射一个连续波,这个波的频率会从一个固定的起始频率开始,逐渐变化至一个固定的终止频率。 阅读详情

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 enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food. 

The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height. 

They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked. 

Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks. 

Input

The input file will contain one or more test cases. The first line of each test case contains an integer n, 
representing the number of different blocks in the following data set. The maximum value for n is 30. 
Each of the next n lines contains three integers representing the values xi, yi and zi. 
Input is terminated by a value of zero (0) for n. 

Output

For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Case case: maximum height = height". 

Sample Input

1
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0

Sample Output

Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342

题意:给你n种立方体,每种立方体有无限多个,求出最高能达到的高度(只要下面的立方体比上面的大,那么就可以堆积上去)

题解:设长宽高分别为x,y,z。那么每种立方体可能提供的高度有3种,分别是x,y,z。所以每种立方体我们只需要保留3个即可,接着我们按x,y进行排序,最底下的当然是x和y最大的。接着按高度求最长上升子序列就行

坑点:同时按x,y来排序可能会出现x特别大,y特别小的情况,所以为了避免这种情况,在建立立方体之前,我们尽量把x,y,z中大的作为长。

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <math.h>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 5e3+100;
#define inf 0x3f3f3f3f
int n;
int dp[maxn];
struct Point
{
    int x,y,z;
}p[maxn];
void add(int x,int y,int z,int i)
{
    p[i].x=x;
    p[i].y=y;
    p[i].z=z;
}
bool cmp(Point a,Point b)
{
    if(a.x==b.x) return a.y>b.y;
    return a.x>b.x;
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int Case=0;
    while(scanf("%d",&n)!=EOF&&n)
    {
        for(int i=0;i<n;i++)
        {
            int x,y,z;
            scanf("%d%d%d",&x,&y,&z);
            add(max(x,z),min(x,z),y,3*i);//一定要取最大和最小
            add(max(x,y),min(x,y),z,3*i+1);
            add(max(z,y),min(z,y),x,3*i+2);
        }
        sort(p,p+3*n,cmp);
        memset(dp,0,sizeof(dp));
        dp[0]=p[0].z;
        int ans=0;
        for(int i=1;i<3*n;i++)
        {
            int M=0;
            for(int j=0;j<i;j++)
            {
                if(p[i].x<p[j].x&&p[i].y<p[j].y&&dp[j]>M)
                {
                    M=dp[j];
                }
            }
            dp[i]=max(dp[i],M+p[i].z);
            ans=max(dp[i],ans);
        }
        printf("Case %d: maximum height = %d\n",++Case,ans);
    }
    return 0;
}

 

Steam Machine换Windows全攻略:分区、驱动与BIOS避坑指南 在客厅游戏PC的演进中,Steam Machine曾是Valve将PC游戏带入电视生态的一次重要尝试。其搭载的SteamOS基于Linux内核,通过Vulkan与Proton兼容层运行Windows游戏,虽然在部分场景下表现出色,但面对反作弊系统、老DX9游戏或第三方软件时,兼容性和维护成本成为明显短板。换用Windows系统,本质上是利用其原生API优势和更完善的NVIDIA/AMD驱动支持,释放硬件性能。操作上,掌握UEFI引导、Secure Boot关闭、AHCI模式切换等BIOS设置,以及分区方案和 阅读详情

相关推荐

从AND到XOR:5种门控电路在PrimeTime中的检查策略差异

本文深入探讨了AND、NAND、OR、NOR和XOR五种门控电路在PrimeTime静态时序分析中的检查策略差异。重点解析了XOR门控因其非单调性而无法被工具自动推断,需要工程师手动配置的特殊性,并提供了针对各类门控的配置模板与调试技巧,以确保时钟网络的完整性与芯片设计的可靠性。

rgv2345678的博客 278

C - Monkey and Banana HDU - 1069 动态规划

C - Monkey and Banana HDU - 1069 动态规划 O(n^2) dp[i] = max (0….dp[i]) + a https://vjudge.net/contest/68966#problem/C #include &lt;string&gt; #include &lt;iostream&gt; #include &lt;vector&gt; #includ...

lilele12211104的专栏 327

Linux 音频驱动(六) ALSA音频驱动之PCM Write数据传递过程

目录1. 前言2. PCM Data Flow3. 总结 1. 前言 本文,我们将以回放(Playback,播放音频)为例,讲解PCM Data是如何从用户空间到内核空间,最后传递到Codec。 在Linux 音频驱动(一) ASoC音频框架简介中,我们给出了回放(Playback)PCM数据流示意图: 对于Linux来说,由于分为 user space 和kernel space,而且两者之间不能随便互相访问。因此用户如果播放音频,则需要调用copy_from_user()将用户数据从user spa

_Modest_的博客 1万+

hdu -1069 Monkey and Banana【贪心+dp】

C - Monkey and Banana Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u SubmitStatus Description A group of researchers are designing an experiment to test the IQ

a915800048的专栏 2228

Zipformer实战:5分钟快速搭建语音识别模型(附LibriSpeech测试结果)

本文提供了一份详细的Zipformer语音识别模型实战指南。通过清晰的步骤,指导读者在5分钟内完成从环境配置、LibriSpeech数据集准备到模型训练与测试的全过程。文章重点解析了关键配置参数,并分享了在LibriSpeech测试集上的性能结果,帮助开发者快速评估和应用这一高效的语音识别架构。

weixin_35578748的博客 173

告别有线:用PVE直通无线网卡,打造一台真正的‘无线’Win10软路由/测试机

本文详细介绍了如何通过PVE直通无线网卡技术,构建全无线Win10软路由或测试机。从硬件选型、PVE环境配置到PCIe和USB双模直通技术,逐步指导实现Wi-Fi AP和蓝牙连接功能,为家庭实验室和小型办公环境提供灵活高效的网络解决方案。

weixin_28683689的博客 600

HDU-1069 Monkey and Banana(动态规划)

HDU-1069 Monkey and Banana(动态规划) 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 mo...

碳酸钙的01妖精的博客 343

SigFit实战:从FEA到光学仿真的热力耦合分析全流程解析

在光机系统与芯片封装等精密工程领域,热与力的耦合效应是影响产品性能与可靠性的核心物理问题。有限元分析(FEA)是预测结构在热、力载荷下变形与应力的基础工具,但其结果通常无法直接用于评估光学性能。这需要一座桥梁,将物理场数据转化为光学设计语言。其核心原理在于数据映射与面形表征技术,例如通过泽尼克多项式拟合,将离散的节点位移分解为离焦、像散等标准光学像差。这项技术的工程价值在于,它实现了多物理场仿真的闭环,使工程师能在设计阶段精准预测热变形或应力对波前误差、调制传递函数等关键光学指标的影响。其典型应用场景包括高

weixin_28630185的博客 367

HDU-1069 Monkey and Banana

Monkey and BananaTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 17886    Accepted Submission(s): 9566Problem DescriptionA group of researchers ...

Low Coder的博客 294

MaxScript批量修改材质、贴图名称

MaxScript批量修改材质、贴图名称1 实现效果1.1 修改前材质、贴图名称1.2 修改后2 代码 1 实现效果 1.1 修改前材质、贴图名称 1.2 修改后 2 代码 prefixName = "prefiname" maxFile = "maxfilepath" makeDir "newBitmappath" mapsPath = newbitmappath + "\\" fn formatStr index = ( str = index as string newS

郑德帅 3249

【Matlab】飞行器气动弹性仿真与分析

气动弹性是飞行器设计领域的核心交叉学科,融合了空气动力学、结构动力学和控制理论,主要研究飞行器结构在气动力作用下的弹性变形、振动响应及相互耦合规律,直接影响飞行器的飞行稳定性、操纵性和结构安全性。随着飞行器向高速度、高机动性、轻量化方向发展,气动弹性问题愈发突出,如颤振、发散、嗡鸣等现象,严重时会导致飞行器结构破坏甚至飞行事故,因此气动弹性仿真与分析已成为飞行器设计、验证和优化的关键环节。当前,飞行器气动弹性仿真面临诸多技术挑战:气动力与结构变形的强耦合特性难以精准描述,易出现仿真误差;

unber的博客 253

C - Monkey and Banana HDU - 1069

[kuangbin带你飞]专题十二 基础DP1; 网址:https://cn.vjudge.net/contest/68966#problem/C C - Monkey and Banana  HDU - 1069  题意:给你n个长方体以及每个的长宽高,这些长方体的数量无限且可以任意旋转。长方体可以叠放在长和宽都比它大的长方体上(不能都相等),问最高能叠多高。

ilblue的博客 823

锐捷-GZ073 网络系统管理赛项赛题第1套A模块-S5配置

锐捷-GZ073 网络系统管理赛项赛题第1套A模块-S5配置

weixin_46183247的博客 774

HDU-1069 Monkey and Banana (贪心+DP)

Monkey and Banana 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 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 buildin...

YOONGI 305

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

【贪心/线性DP】Monkey and Banana(HDU-1069)

【线性DP】Monkey and Banana(HDU-1069) 题目链接 题目 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 th

鱼竿钓鱼干 196

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

HDU1069Monkey and Banana(贪心?DP?)

解题思路:一开始想到背包- -,果然还是水平低AC代码如下:#include&lt;stdio.h&gt; #include&lt;string.h&gt; #include&lt;iostream&gt; #include&lt;algorithm&gt; using namespace std; struct node { int l,w,h; }data[1010]; int cmp(...

小胡同的诗 366

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

HDU 1069 TOJ 1322 Monkey and Banana(贪心+dp)

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...

珈凝的博客 306

HDU1069:Monkey and Banana(DP+贪心)

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 som

ACM!荣耀之路! 1449

hdu1069 Monkey and Banana(dp+贪心)

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87287#problem/C 题意:给出n个长方体的三边2,求能叠的最高高度,要求上面的长方体的底面积要小于下面的(长宽都要小于),每个长方体可以无限取 思路:一个箱子,可以有六种情况,当成6种排序,然后发现和最长递减子序列很相似. 可以用类似的思路求解 . 首先对各种尺寸

li1004133206的专栏 453

HDU1069 Monkey and Banana【基础DP】

Monkey and Banana 题意: 有n种类型的砖块,每种类型的砖块都有无限个。第i块砖块的长宽高分别用xi,yi,zi来表示。 同时,由于砖块是可以旋转的,每个砖块的3条边可以组成6种不同的长宽高。在构建塔时,当且仅当A砖块的长和宽都分别小于B砖块的长和宽时,A砖块才能放到B砖块的上面,计算最高可以堆出的砖块们的高度。 题解: 因为一块砖有六个形态,直接将每个形态确定为一种砖块,然后排好序(随便以什么依据,但一定要排好序)。要明确一点,是不能用贪心做的,因为也许在A砖上放置了B,不...

lllllan 166

HDU - 1069 Monkey and Banana

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 enough, it shall be able to reach the banan

AiChiMomo的博客 205

HDU1069(Monkey and Banana)

题目传送门 题意 题目大概意思就是说给定你很多的长方体,把这些长方体叠加起来问可以达到的最大高度是多少,叠加是有前提的,上面的长方体的长宽必须严格小于下面的长方体长宽,不能存在一个小于一个相等的情况,每个长方体可以无限次使用。 思路 错误的想法:按照面积来,但是仔细想想77 和 68的两个长方形面虽然后面的长方形面积小,但是这两个长方形都不能放在彼此的上面,所以这种做法是错误的,最开始也是打算这...

weixin_43808717的博客 397

HDU 1069 Monkey and Banana

原题目链接:HDU1069 分类 HDU 动态规划 贪心 题意 题意是堆箱子、要求上面的箱子的长和宽都小于下面箱子的长和宽 想法 因为每块砖有三种摆法(高和底面积不同),可以把这三种情况当成不同的三块砖,加入brick数组中。注意,一定要分清长和宽,长要比宽长,这样在后面dp的过程中可以保证长边和长边比较、短边和短边比较。 所以 要么保证长比宽长,每次录入3个面 要么每次录入6个面 因为这...

GatesMa's blog 576

Monkey and Banana HDU - 1069

//贪心 #include<cstdio> #include<algorithm> using namespace std; struct Brick { int x,y,z;//长宽高 }brick[200]; int ant; void UpDate(int x,int y,int z) { brick[ant].x = x; brick[ant]...

❂ 195

HDU——1069【Monkey and Banana】

【题意】: 有人要做实验,看看猴子的智商,在屋顶上边挂着吃的东西,然后给你一些木块的长、宽、高,问你猴子最高可以爬多高,下面的木块必须大于(不能等于)上面的木块。 【思考】: 感觉像贪心,但还要多一点dp的味道,如果你可以看出这是一个严格递增子序列的问题,那最好了,可惜我没看出来,所以用了dp,dp转移方程为:dp[i]=max( dp[i],dp[j]+hi[i]) ,所以开始码起来  ^...

sf_yang35的博客 217

Monkey and Banana(HDU-1069)

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...

qq_40634175的博客 199
上一篇: HDU6321 Dynamic Graph Matching(状态dp,类比于背包问题)
下一篇: Max Sum Plus Plus (dp+滚动数组)
untilyouydc
博客等级 码龄9年 650粉丝 481原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值