DP问题,我是按照边排序的,排序既要考虑x也要考虑y,同时在每个面中,长宽也要有序。还有注意状态转移,当前高度并不是之前的最大block叠加的高度,而是可叠加最大高度+当前block高度或者是当前block高度。最后,n^2的复杂度。

#include <stdio.h>
#include <stdlib.h> #define MAXTYPE 33
#define MAXNUM 3*MAXTYPE typedef struct {
int x, y, z;
} rect; rect rects[MAXNUM];
int heights[MAXNUM]; int comp(const void *a, const void *b) {
if ( ((rect *)a)->x - ((rect *)b)->x )
return ((rect *)a)->x - ((rect *)b)->x;
else
return ((rect *)a)->y - ((rect *)b)->y;
} void addOth(int i) {
int tmp;
int x = rects[i].x;
int y = rects[i].y;
int z = rects[i].z; //
tmp = (y<z) ? y:z;
rects[i+].x = tmp;
rects[i+].y = y+z-tmp;
rects[i+].z = x; //
tmp = (x<z) ? x:z;
rects[i+].x = tmp;
rects[i+].y = x+z-tmp;
rects[i+].z = y; //
tmp = (x<y) ? x:y;
rects[i].x = tmp;
rects[i].y = x+y-tmp;
} int mymax(int a, int b) {
return a>b ? a:b;
} int main() {
int n, total;
int i, j, tmp;
int case_n = ; while (scanf("%d", &n)!=EOF && n) {
case_n ++; for (i=; i<*n; i=i+) {
scanf("%d %d %d", &rects[i].x, &rects[i].y, &rects[i].z);
addOth(i);
} total = *n;
qsort(rects, total, sizeof(rect), comp); /*
for (i=0; i<total; ++i)
printf("%d: %d, %d, %d\n", i, rects[i].x, rects[i].y, rects[i].z);
*/ heights[] = rects[].z;
for (i=; i<total; ++i) {
tmp = ;
for (j=i-; j>=; --j) {
if (rects[j].x<rects[i].x && rects[j].y<rects[i].y && heights[j]>tmp)
tmp = heights[j];
}
heights[i] = mymax(tmp+rects[i].z, rects[i].z);
} tmp = ;
for (i=; i<total; ++i) {
if (heights[i] > tmp)
tmp = heights[i];
} printf("Case %d: maximum height = %d\n", case_n, tmp);
} return ;
}

【HDOJ】1069 Monkey and Banana的更多相关文章

  1. 【HDOJ】1512 Monkey King

    左偏树+并查集.左偏树就是可合并二叉堆. /* 1512 */ #include <iostream> #include <string> #include <map&g ...

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

  3. HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)

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

  4. HDU 1069 Monkey and Banana dp 题解

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

  5. 【转】Android Monkey 命令行可用的全部选项

    常规 事件 约束限制 调试 原文参见:http://www.douban.com/note/257030384/ 常规 –help 列出简单的用法. -v 命令行的每一个 -v 将增加反馈信息的级别. ...

  6. HDU 1069—— Monkey and Banana——————【dp】

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 1069 Monkey and Banana(二维偏序LIS的应用)

    ---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  8. HDU 1069 Monkey and Banana (DP)

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. hdu 1069 Monkey and Banana

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

随机推荐

  1. javascript 第27节 jQuery选择器

    下面的html需要以下2个文件: 1.style.css div,span,p { width:140px; height:140px; margin:5px; background:#aaa; bo ...

  2. 10_Jaxws使用自定义pojo发布服务

    [简述] 查询三天的天气信息(天气概况.日期.温度),测试jaxws是否支持自定义pojo发布服务. [开发过程] 服务端: 1.自定义pojo(天气概况.日期.温度) 2.开发SEI接口及实现类 3 ...

  3. day20 在php中通过php语句操作数据库

    第一步:连接数据库服务器 mysql_connect("数据库服务器地址","用户名","密码") 第二步:设定跟数据库打交道的网页的编码 ...

  4. .NET高端职位招聘要求

    系统架构师: 1.硕士及以上学历,博士有项目成果者优先: 2.五年以上工作经验,三年以上互联网经验,一年以上大型软件项目总体设计.分析.架构经验,有移动互联网或云计算虚拟化系统设计开发经验者优先: 3 ...

  5. 前端资源多个产品整站一键打包&包版本管理(一)

    来新公司工作的第五个月.整站资源打包管理也提上了日程. 问题: 首先.什么是整站的打包管理呢? 我们公司的几个重要产品都在同一个webapp里面,但是,不同的开发部门独立开发不同的产品,长期以来,我们 ...

  6. PHP LINUX Notice: undefined $_GET完美解决方法

    PHP Notice: undefined 平时用$_GET[‘xx’] 取得参数值时,如果之前不加判断在未传进参数时会出现这样的警告: PHP Notice: undefined index xxx ...

  7. Oracle 排序分析函数之ROW_NUMBER、RANK和DENSE_RANK

    我们都知道分析函数功能很强大,可能需要写很复杂的标准SQL才能办到或不可能办到的事,使用分析函数却能很容易完成.我们经常会用到排序分析函数,如ROW_NUMBER,RANK,DENSE_RANK.这三 ...

  8. 认识基本的UI资源

    什么是UI精灵(Sprite) 在制作UI时,经常将一些零碎的小的UI资源(比如,一个小箭头,一个按钮等)打包成一张大图,然后在使用时,只使用这个大图中的一部分,那么这一块"被切出来&quo ...

  9. C# dynamic

    [TestMethod] public void DynamicTest() { dynamic Customer = new ExpandoObject(); Customer.Name = &qu ...

  10. CSS 居中方法集锦(*******************************)

      记录收集纯CSS层面实现的水平.垂直居中方法可用于块级.行内快.内联元素以及文字图片等. 水平或垂直居中 1.1 text-align1.2 margin1.3 line-height1.4 pa ...