The Tower of Babylon

题意:给你n种石头,长x,宽y,高z,每种石头数目无限,一块石头能放到另一块上的条件是:长和宽严格小于下面的石头。问叠起来的最大高度。

/*
有些类似“叠箱子”问题,看起来一种砖有无限多个,其实最多只能用到两次。
说下我的思路吧,一块砖有3个数据,虽然3!=6,但本质上还是只有3种,把这三种都表示出来,使x<=y;这样就有了3n组数据。因为我不会建图,就把这3n组数据再排列一下,使一块砖只能放到它后面的砖之上,而绝不能放到之前的砖上,即按x为一级y为二级升序排列,结合之前的x<=y,就能达到目的了。
*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef struct
{
int arr[];
}Box;
Box a[];
bool cmp(Box a,Box b)
{
if(a.arr[]!=b.arr[])
return a.arr[] < b.arr[];
else if(a.arr[] != b.arr[])
return a.arr[] < b.arr[];
else return a.arr[] < b.arr[];
}
int ok(Box a,Box b)
{
return (a.arr[] < b.arr[] && a.arr[] < b.arr[]);
}
int main()
{
//freopen("Cola.in","r",stdin);
int n,m=,i,j,t,max;
while(cin>>n,n)
{
m++;
for(i = ; i < *n; i += )
{
cin>>a[i].arr[]>>a[i].arr[]>>a[i].arr[];
sort(a[i].arr,a[i].arr+);
a[i+].arr[] = a[i].arr[];
a[i+].arr[] = a[i].arr[];
a[i+].arr[] = a[i].arr[];
a[i+].arr[] = a[i].arr[];
a[i+].arr[] = a[i].arr[];
a[i+].arr[] = a[i].arr[];
}
sort(a,a+*n,cmp);
max = ;
for(i = *n-; i >= ; i--)
{
t = a[i].arr[];
for(j = i+; j < *n; j++)
{
if(ok(a[i],a[j]) && a[i].arr[]+a[j].arr[] > t)
t = a[i].arr[]+a[j].arr[];
}
a[i].arr[] = t;
if(t > max) max = t;
}
printf("Case %d: maximum height = %d\n",m,max);
}
return ;
}

poj2241 The Tower of Babylon的更多相关文章

  1. POJ2241——The Tower of Babylon

    The Tower of Babylon Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2207   Accepted: 1 ...

  2. UVa 437 The Tower of Babylon(经典动态规划)

    传送门 Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details ...

  3. UVa 437 The Tower of Babylon

    Description   Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of ...

  4. UVA 437 十九 The Tower of Babylon

    The Tower of Babylon Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

  5. UVA437-The Tower of Babylon(动态规划基础)

    Problem UVA437-The Tower of Babylon Accept: 3648  Submit: 12532Time Limit: 3000 mSec Problem Descrip ...

  6. DAG 动态规划 巴比伦塔 B - The Tower of Babylon

    题目:The Tower of Babylon 这是一个DAG 模型,有两种常规解法 1.记忆化搜索, 写函数,去查找上一个符合的值,不断递归 2.递推法 方法一:记忆化搜索 #include < ...

  7. HOJ 1438 The Tower of Babylon(线性DP)

    The Tower of Babylon My Tags Cancel - Seperate tags with commas. Source : University of Ulm Internal ...

  8. uva The Tower of Babylon[LIS][dp]

    转自:https://mp.weixin.qq.com/s/oZVj8lxJH6ZqL4sGCXuxMw The Tower of Babylon(巴比伦塔) Perhaps you have hea ...

  9. [动态规划]UVA437 - The Tower of Babylon

     The Tower of Babylon  Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many d ...

随机推荐

  1. (扫盲)jQuery extend()和jQuery.fn.extend()的区别

    1.认识jQuery extend()和jQuery.fn.extend() jQuery的API手册中,extend方法挂载在jQuery和jQuery.fn两个不同对象上方法,但在jQuery内部 ...

  2. 如何修改硬盘挂载的名字LABEL

    ➜ ~ df -h Filesystem Size Used Avail Use% Mounted on/dev/sda2 114G 97G 12G 90% /media/brian/4ef34b75 ...

  3. python之学习

    ------------------------------------------  基本语句解析 import:导入某些模块或者文件 import random: 导入生成随机数模块 import ...

  4. 草原psd素材

    草原PSD素材,草原,风景,蓝天白云,飞鸟,阳光,绿色,草地. http://www.huiyi8.com/caoyuan/psd/

  5. IDEAL葵花宝典:java代码开发规范插件 (maven helper)解决maven 包冲突的问题

    小编说到: 在我们日常开发当中常常我们会遇到JAR包冲突.找来找去还找不到很是烦人.那么所谓的JAR包冲突是指的什么那?JAR包冲突就是-引入的同一个JAR包却有好几个版本. 例如: 项目中引用了两个 ...

  6. DenseNet算法详解——思路就是highway,DneseNet在训练时十分消耗内存

    论文笔记:Densely Connected Convolutional Networks(DenseNet模型详解) 2017年09月28日 11:58:49 阅读数:1814 [ 转载自http: ...

  7. vs中解决方案、项目、类及ATL的理解

    解决方案,是对所有要完成工作的统称,一般叫Solution. 项目,也叫工程,是将解决方案分成若干个模块进行处理,一般叫做Project.添加项目就是添加工程.解决方案是所有项目的总和. 一个项目里面 ...

  8. java中路径的获取

    网上摘录 (1).request.getRealPath("/");//不推荐使用获取工程的根路径 (2).request.getRealPath(request.getReque ...

  9. leetcode 43. Multiply Strings(高精度乘法)

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  10. 浅析C语言中strtol()函数与strtoul()函数的用法

    转自:http://www.jb51.net/article/71463.htm C语言strtol()函数:将字符串转换成long(长整型数) 头文件: ? 1 #include <stdli ...