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. croppic 图片裁剪

    #region 3.1.3 保存裁剪后的图片方法 +ContentResult TemplateCropImg() /// <summary> /// 保存裁剪后的图片方法 /// < ...

  2. ###STL学习--vector

    点击查看Evernote原文. #@author: gr #@date: 2014-08-11 #@email: forgerui@gmail.com vector的相关问题.<stl学习> ...

  3. C#中常用修饰符

    1.存取修饰符 public:(公有的)存取不受限制 protected:(受保护的)只有包含该成员的类以及派生类可以存取  private:(私有的)只有包含该成员的类可以使用 2.类修饰符 abs ...

  4. ubuntu 恢复gnome-panel

    Ubuntu重启panel 的方法首先进入终端, 依次输入以下命令1.gconftool --recursive-unset /apps/panel2.rm -rf ~/.gconf/apps/pan ...

  5. 高能物理/HyperPhysics的网站/Website

    参考: 基础物理-高能物理[Hyperphysics]

  6. JS 页面打印

    var hkey_root, hkey_path, hkey_key hkey_root = "HKEY_CURRENT_USER" hkey_path = "\\Sof ...

  7. 【BZOJ】1053: [HAOI2007]反素数ant

    1053: [HAOI2007]反素数ant Description: g(x)表示x的约数个数,反素数:对于任意的i (i < x),均有g(i) < g(x),则x为反素数:现在输入不 ...

  8. GCC交叉编译链命名

    命名格式: arch[-vendor][-os]-abi arch:CPU的架构 vendor:工具链的供应商 os: 目标上运行的操作系统,不同的操作系统对应着不同的C库,例如 newlib.gli ...

  9. navigationController Pop回指定页面

    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIn ...

  10. String类中常用的操作

    一.获取: 1.获取字符串的长度(注意是方法,不是跟数组的属性一样的) int length(); 1 public static void getLength(){ 2 String s = &qu ...