HDU1069 Monkey and Banana

题目大意

给定 n 种盒子, 每种盒子无限多个, 需要叠起来, 在上面的盒子的长和宽必须严格小于下面盒子的长和宽, 求最高的高度.

思路

对于每个方块, x, y, z 的全排列共有 6 种可能性, 每种可能性只需要一个方块, 因为方块必须严格小于, 若有两个相同的方块, 则不符合题意.

先将方块按照 x, y 依次进行排序

设 dp[i] 为第 i 个方块时的最高高度, 则每个方块的最高高度为 dp[i] = max(dp[j] + arr[i].z). 每次处理 i 时均默认该方块加入叠成的塔中, 对于后面的状态, 可以不选择这个状态.

代码

package 基础DP1;

import java.util.Arrays;
import java.util.Scanner; class Block implements Comparable<Block>{
int x, y, z;
Block(int _x, int _y, int _z) {
x = _x; y = _y; z = _z;
}
@Override
public int compareTo(Block arg0) {
if(x != arg0.x)
return x - arg0.x;
return y - arg0.y;
} }
public class HDU1069 { public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int round = 0;
while(true) {
int nBlock = in.nextInt();
if(0 == nBlock)
break;
Block[] arr = new Block[nBlock * 6 + 1];
for(int i = 1; i <= nBlock * 6; ) {
int x = in.nextInt();
int y = in.nextInt();
int z = in.nextInt();
arr[i++] = new Block(x, y, z);
arr[i++] = new Block(x, z, y);
arr[i++] = new Block(y, x, z);
arr[i++] = new Block(y, z, x);
arr[i++] = new Block(z, y, x);
arr[i++] = new Block(z, x, y);
}
Arrays.sort(arr, 1, arr.length);
int[] dp = new int[nBlock * 6 + 1];
int ans = 0;
for(int i = 1; i <= nBlock * 6; i++) {
// System.out.println("x is" + arr[i].x + " y is " + arr[i].y + " z is " + arr[i].z);
int maxHeight = 0;
for(int j = 1; j < i; j++) {
if(arr[j].x >= arr[i].x || arr[j].y >= arr[i].y)
continue;
maxHeight = Math.max(maxHeight, dp[j]);
}
dp[i] = maxHeight + arr[i].z;
ans = Math.max(ans, dp[i]);
} System.out.printf("Case %d: maximum height = %d", ++round, ans);
System.out.println();
}
} }

HDU1069 Monkey and Banana的更多相关文章

  1. kuangbin专题十二 HDU1069 Monkey and Banana (dp)

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

  2. HDU1069 Monkey and Banana —— DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS ...

  3. HDU1069:Monkey and Banana(DP+贪心)

    Problem Description A group of researchers are designing an experiment to test the IQ of a monkey. T ...

  4. HDU-1069 Monkey and Banana DAG上的动态规划

    题目链接:https://cn.vjudge.net/problem/HDU-1069 题意 给出n种箱子的长宽高 现要搭出最高的箱子塔,使每个箱子的长宽严格小于底下的箱子的长宽,每种箱子数量不限 问 ...

  5. HDU1069 - Monkey and Banana【dp】

    题目大意 给定箱子种类数量n,及对应长宽高,每个箱子数量无限,求其能叠起来的最大高度是多少(上面箱子的长宽严格小于下面箱子) 思路 首先由于每种箱子有无穷个,而不仅可以横着放,还可以竖着放,歪着放.. ...

  6. HDU1069 Monkey and Banana(dp)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意:给定n种类型的长方体,每个类型长方体无数个,要求长方体叠放在一起,且上面的长方体接触面积要小于 ...

  7. hdu1069 Monkey and Banana LIS

    #include<cstdio> #include<iostream> #include<algorithm> #include<queue> #inc ...

  8. ACM-经典DP之Monkey and Banana——hdu1069

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

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

随机推荐

  1. [linux]解决DNS配置重启丢失

    DNS配置重启丢失 每次重启后都修改DNS配置文件 /etc/resolv.conf从网上得知 /etc/resolv.conf中的DNS配置是从/etc/resolvconf/resolv.conf ...

  2. Linux 下安装 Memcached 和 PHP 开启 Memcached 扩展 及 LAMP 环境的安装

    http://blog.csdn.net/liruxing1715/article/details/8269563

  3. vsftpd配置文件解析

    对vsftpd配置文件详细解答. 1.默认配置: 1>允许匿名用户和本地用户登陆. anonymous_enable=YES local_enable=YES 2>匿名用户使用的登陆名为f ...

  4. React.js 小书 Lesson11 - 配置组件的 props

    作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson11 转载请注明出处,保留原文链接和作者信息. 组件是相互独立.可复用的单元,一个组件可能在不 ...

  5. c#中日期的处理

    DateTime.Now.ToShortDateString()//只取日期DateTime.Now.ToLongTimeString();//只取时间搞定DateTime.Now.ToShortTi ...

  6. 从零开始的全栈工程师——underscore

    underscore 是js封装的一个js库 库和框架是有区别的 mvc框架就是backbone就是依赖这个库underscore就是定义了一个_( 下划线对象 ); 函数库的所有的方法都归属于这个对 ...

  7. 002Angular2工程目录解构

    |--my-app 工程名 |--e2e 端到端测试 |--node_modules package.json列出的第三方模块放在此处 |--src |--app |--app.component.c ...

  8. Popularize what is heart of mobile phone?

    From: http://tech.sina.com.cn/mobile/n/2014-09-29/08399657494.shtml 只谈核数没意义 带你重新认识手机SoC 2014年09月29日  ...

  9. 关于 document.compatMode

    今天查资料时无意发现一个以前没有注意到过的属性:document.compatMode 经过一番资料的查询后,了解到以下信息: 我们都知道IE有两种盒子模型,在不声明 !DOCTYPE 时是混杂模式 ...

  10. 字符串安全处理:CRT安全增强以及安全模板重载

    Secure Template Overloads :http://msdn.microsoft.com/en-us/library/ms175759(v=vs.80).aspx Security E ...