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. 第一篇、HTML标签

    <!--根标签--> <html> <head> <!--设置编码方式--> <meta charset="UTF-8"> ...

  2. (已实现)相似度到大数据查找之Mysql 文章匹配的一些思路与提高查询速度

    需求,最近实现了文章的原创度检测功能,处理思路一是分词之后做搜索引擎匹配飘红,另一方面是量化词组,按文章.段落.句子做数据库查询,功能基本满足实际需求. 接下来,还需要在海量大数据中快速的查找到与一句 ...

  3. C# ACM poj1005

    大水题呀 public static void acm1005(int n, float[,] a) { float pi = 3.1415926f, rr; int years; ; i < ...

  4. javascript 第26节 jQuery对象

    <html> <head> <title>jQuery</title> <!--导入jquery库--> <script type=& ...

  5. Trie的C++实现及HDU1251,hdu1671

    #include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...

  6. HttpWatch网络抓包工具的使用

    HttpWatch网络抓包工具是专为IE浏览器集成的一款网络拽包工具.   是一款强大的网页数据分析软件,是最好用的抓包工具,httpwatch可以抓到上传视屏图片的包,一般的抓包软件是抓不到的.打开 ...

  7. C++ const修饰函数、函数参数、函数返回值

    const修饰函数 在类中将成员函数修饰为const表明在该函数体内,不能修改对象的数据成员而且不能调用非const函数.为什么不能调用非const函数?因为非const函数可能修改数据成员,cons ...

  8. 让hyper-v虚拟机中类ubuntu系统可以全屏

    很久之前一直都没有方法让linux虚拟机支持hyper-v的全屏,只能以1024x768或者800x600等方形屏幕 如果是windows7以前的电脑,可以用mstsc远程桌面修改分辨率,window ...

  9. 关于css中overflow:hidden的使用

    overflow:hidden有两个用处经常用到: 1.通过设定自身的高度,加上overflow:hidden可以隐藏超过容器本身的内容:     但是,小编在以往的使用中,发现了一个问题,只要父级容 ...

  10. object-fit: 炒鸡方便的图片居中方法

    今天在项目中遇到图片居中的问题,嗯,之前也有写过解决这个问题的文章,有n种方法.不过今天要说一个新的方案:object-fit ,嗯,这个才是真的方便的方案啊. 先看预览: object-fit 只能 ...