每一个长方形都有六种放置形态,其实可以是三种,但是判断有点麻烦直接用六种了,然后按照底面积给这些形态排序,排序后就完全变成了LIS的问题。代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 1818
struct Node
{
int x,y,z,area;
void init(int a,int b,int c)
{
x = a;
y = b;
z = c;
area = x*y;
}
} blo[N];
bool cmp(Node a,Node b)
{
return a.area > b.area;
}
int main()
{
int n,z,a,b,c,cnt,dp[N],ca=;
// freopen("1.in.cpp","r",stdin);
while(cin>>n)
{
if(n==) break;
cnt = ;
for(int i = ; i < n; i++)
{
cin>>a>>b>>c;
blo[cnt++].init(a,b,c);
blo[cnt++].init(b,a,c);
blo[cnt++].init(c,b,a);
blo[cnt++].init(b,c,a);
blo[cnt++].init(a,c,b);
blo[cnt++].init(c,a,b);
}
sort(blo,blo+cnt,cmp);
for(int i = ; i < cnt; i++) dp[i] = blo[i].z;
for(int i = ; i < cnt; i++)
{
for(int j = ; j < i; j++)
{
if(blo[i].x < blo[j].x && blo[i].y < blo[j].y)
{
dp[i] = max(dp[i],dp[j]+blo[i].z);
}
}
}
int ans = ;
for(int i = ; i < cnt;i++) ans = max(ans,dp[i]);
printf("Case %d: maximum height = %d\n",++ca,ans);
}
return ;
}

UVA - 437 The Tower of Babylon(dp-最长递增子序列)的更多相关文章

  1. UVa 437 The Tower of Babylon(DP 最长条件子序列)

     题意  给你n种长方体  每种都有无穷个  当一个长方体的长和宽都小于还有一个时  这个长方体能够放在还有一个上面  要求输出这样累积起来的最大高度 由于每一个长方体都有3种放法  比較不好控制 ...

  2. UVA 437 The Tower of Babylon(DAG上的动态规划)

    题目大意是根据所给的有无限多个的n种立方体,求其所堆砌成的塔最大高度. 方法1,建图求解,可以把问题转化成求DAG上的最长路问题 #include <cstdio> #include &l ...

  3. [DP]最长递增子序列

    #include <iostream> #include <limits.h> #include <vector> #include <algorithm&g ...

  4. HDU-1160-FatMouse's Speed(DP, 最长递增子序列)

    链接: https://vjudge.net/problem/HDU-1160 题意: FatMouse believes that the fatter a mouse is, the faster ...

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

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

  6. UVa 437 The Tower of Babylon

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

  7. DP(DAG) UVA 437 The Tower of Babylon

    题目传送门 题意:给出一些砖头的长宽高,砖头能叠在另一块上要求它的长宽都小于下面的转头的长宽,问叠起来最高能有多高 分析:设一个砖头的长宽高为x, y, z,那么想当于多了x, z, y 和y, x, ...

  8. UVA 437 The Tower of Babylon巴比伦塔

    题意:有n(n≤30)种立方体,每种有无穷多个.要求选一些立方体摞成一根尽量高的柱子(可以自行选择哪一条边作为高),使得每个立方体的底面长宽分别严格小于它下方立方体的底面长宽. 评测地址:http:/ ...

  9. UVA 437 "The Tower of Babylon" (DAG上的动态规划)

    传送门 题意 有 n 种立方体,每种都有无穷多个. 要求选一些立方体摞成一根尽量高的柱子(在摞的时候可以自行选择哪一条边作为高): 立方体 a 可以放在立方体 b 上方的前提条件是立方体 a 的底面长 ...

随机推荐

  1. LeetCode OJ 48. Rotate Image

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  2. UILabel设置富文本格式显示

    实例化方法和使用方法 实例化方法: 使用字符串初始化 - (id)initWithString:(NSString *)str; 例: NSMutableAttributedString *Attri ...

  3. 批量去除office超链接

    mac下: fn+shift+comman+F9 windows下:control+shift+F9

  4. String类中一些常用的函数

    1 CharAt(index) : 通过他的索引来获取元素 @Test public void test1(){ String a="dfjkdjfd134"; for(int i ...

  5. 与导航栏下控件的frame相关的edgesForExtendedLayout、translucent、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets等几个属性的详解

    在引入了导航控制器UINavigationController和分栏控制器UITabBarController之后,我们在设置控件的frame的时候就需要注意避开导航栏UINavigationBar ...

  6. javaWEB总结(7):HttpServlet和HttpServletRequest

    前言:HttpServletRequest对象封装了客户端进行HTTP协议请求时的所有信息,HttpServletRequest继承了ServletRequest,所以和ServletRequest一 ...

  7. OC-之AFNetworking与ASIHTTPRequest对比

    一.底层实现 1.AFN的底层实现基于OC的NSURLConnection和NSURLSession 2.ASI的底层实现基于纯C语言的CFNetwork框架 3.因为NSURLConnection和 ...

  8. iOS不可变字符串的所有操作

    可以直接复制代码即可运行看看结果,方便理解 //NSString //OC字符串不能用printf输出 //但是遗憾的是OC没有一个从终端读取数据的方式,需要使用scanf读取C字符串然后转换成OC的 ...

  9. ASP.NET MVC 使用带有短横线的html Attributes

    我们常常需要一个文本框来输入用户名,在asp.net mvc 中可以使用 TextBoxFor.有时候我们想为这个文本框添加一些特性,比如 html5 的data-,如果直接写data-是会提示错误的 ...

  10. Django:之BBS项目

    首先新建一个BBSProject项目,在建一个app,把app导入到项目中. 在项目BBSProject中的settings.py中, INSTALLED_APPS = [ 'django.contr ...