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. mooc_java Socket

    Socket通信,TCP协议是面向连接,可靠的,有序的,以字节流的方式发送数据:基于TCP协议实现网络通信的类客户端的Socket类 服务器端的ServerSocket类 -------------- ...

  2. 思科安全:加密流量威胁检测、加密流量威胁和恶意软件检测、识别无线干扰或威胁、Talos 情报源可加强对已知和新型威胁的防御、分布式安全异常检测

    思科DNA竞品比较工具 您的网络能够驱动数字化转型吗? 根据IDC调查,45%的受调研公司计划在未来两年内做好网络数字化的准备.查看数字化网络带来的结果和商业价值. 下载报告 思科 HPE 华为 Ar ...

  3. mysql修改初始密码

    通过MySQL命令行,可以修改MySQL数据库的密码,下面就为您详细介绍该MySQL命令行,如果您感兴趣的话,不妨一看. 格式:mysqladmin -u用户名 -p旧密码 password 新密码 ...

  4. [算法]Trie树

    我是好文章的搬运工,原文来自博客园,博主一线码农,选自”6天通吃树结构“系列,地址:http://www.cnblogs.com/huangxincheng/archive/2012/11/25/27 ...

  5. 洛谷P2983 [USACO10FEB]购买巧克力Chocolate Buying

    题目描述 Bessie and the herd love chocolate so Farmer John is buying them some. The Bovine Chocolate Sto ...

  6. ssh免密脚本

    #!/bin/sh if [ "$1"x = ""x ]; then echo "usage:/opt/bin/auto-ssh.sh user se ...

  7. C# 序列化反序列化XML的帮助类

    以下是一个包装的用于序列化反序列化XML和C# 对象的类.  public class XmlSerializeHelper<T>     {         #region Serial ...

  8. Visual Studio 编译后去掉只读属性

    Visual Studio 编译后去掉只读属性 attrib $(TargetPath) -R attrib $(TargetDir)$(TargetName).pdb -R

  9. 五 python 发送邮件

    需求: 系统中使用一个邮箱(这里用QQ)给其他邮箱发消息,用python完成,步骤如下: 1: 开启QQ邮箱的SMTP服务.设置-> 账号 2: 开启邮箱服务:这个需要手机验证,最后会给你一个授 ...

  10. java 通过System.getProperties()获取系统参数

    转自:https://www.cnblogs.com/ksuifeng/archive/2010/09/25/1834416.html 1.java的System.getProperty()方法可以获 ...