http://acm.hdu.edu.cn/showproblem.php?pid=1069

意思就是给定n种箱子,每种箱子都有无限个,每种箱子都是有三个参数(x, y, z)来确定。

你可以选任意两个参数作为长和宽,第三个是高。

然后要求把箱子搭起来,使得高度最高。

能搭的前提是下面那个箱子的长和宽都 > 上面那个箱子的。

思路:

因为同一个箱子可以产生6中不同的箱子,而每种最多选一个,因为相同的箱子最多只能搭起来一个。

那么可以把所有箱子都弄出来,排序,就是LIS的题目了。

dp[i]表示以i这个箱子为结尾的最大高度。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
int n;
struct node {
int L, W, H;
node(int LL, int WW, int HH) : L(LL), W(WW), H(HH) {}
node() {}
bool operator < (const struct node & rhs) const {
if (L != rhs.L) return L > rhs.L;
else if (W != rhs.W) return W > rhs.W;
else return H > rhs.H;
}
}a[maxn];
int dp[maxn];
bool isok(int one, int two) {
if (a[one].L > a[two].L && a[one].W > a[two].W) return true;
else return false;
}
void work () {
int t = ;
for (int i = ; i <= n; ++i) {
int x, y, z;
cin >> x >> y >> z;
a[++t] = node(x, y, z);
a[++t] = node(x, z, y);
a[++t] = node(y, x, z);
a[++t] = node(y, z, x);
a[++t] = node(z, x, y);
a[++t] = node(z, y, x);
}
sort(a + , a + + t);
for (int i = ; i <= t; ++i) {
dp[i] = a[i].H;
for (int j = ; j < i; ++j) {
if (isok(j, i)) {
dp[i] = max(dp[i], dp[j] + a[i].H);
}
}
}
int ans = -inf;
for (int i = ; i <= t; ++i) {
ans = max(ans, dp[i]);
}
static int f = ;
printf("Case %d: maximum height = %d\n", ++f, ans);
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
// IOS;
while (cin >> n && n) work();
return ;
}

HDU 1069 Monkey and Banana DP LIS变形题的更多相关文章

  1. HDU 1069 Monkey and Banana DP LIS

    http://acm.hdu.edu.cn/showproblem.php?pid=1069 题目大意 一群研究员在研究猴子的智商(T T禽兽啊,欺负猴子!!!),他们决定在房顶放一串香蕉,并且给猴子 ...

  2. hdu(1069)——Monkey and Banana(LIS变形)

    题意: 如今给你n个石块,然后它由坐标来表示(x,y,z).可是它能够有不同的方法,也就是说它的三个坐标能够轮换着来的. 石块的数量不限,可是每次都必须保持上底面的长和宽严格递减,然后问你用这些石块所 ...

  3. HDU 1069 monkey an banana DP LIS

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64uDescription 一组研究人员正在 ...

  4. HDU 1069 Monkey and Banana dp 题解

    HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...

  5. HDU 1069 Monkey and Banana (DP)

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 1069 Monkey and Banana(DP 长方体堆放问题)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

  7. HDU 1069 Monkey and Banana(LIS最长上升子序列)

    B - LIS Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descripti ...

  8. 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 ...

  9. HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...

随机推荐

  1. Nginx HTTP Server相关

    一.Nginx安装: 采取手动编译安装 对多种重要的选项进行配置 安装前提:常用工具和库,GCC PCRE(Rewrite模块需要) pcre-devel(源码) zlib zlib-devel(源码 ...

  2. Codeforces617E XOR and Favorite Number(分块 异或)

    Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is g ...

  3. C#如何立即回收内存

    1.把对象赋值为null 2.立即调用GC.Collect(); 注意:这个也只是强制垃圾回收器去回收,但具体什么时候执行不确定.  代码: class Test { ~Test() { Consol ...

  4. Arduino 视频教程

    http://v.youku.com/v_show/id_XNDU1MjI4MzA4.html?from=y1.2-1-176.3.12-2.1-1-1-11

  5. scores

    题意: m维偏序问题. 解法: 考虑对每一维按照每一个元素在这一维的数值分块,对于每一个块维护一个大小为 n 的bitset,表示前缀/后缀满足条件的元素集合. 对于每一个询问,我们可以枚举找到相应的 ...

  6. sublime取消自动升级提示

    1.进入Preferences -> Settings-User ,添加 "update_check": false, 2.重启Sublime.

  7. 爬虫之BeautifulSoup, CSS

    1. Beautiful Soup的简介 2. Beautiful Soup 安装 可以利用 pip 或者 easy_install 来安装,以下两种方法均可 easy_install beautif ...

  8. Mysql定时执行任务实现方法

    http://blog.csdn.net/zlp5201/article/details/38309095

  9. 下载win7/win8/win10镜像

    关于给电脑换系统,很多人会花钱去电脑店里换,或者是下载Ghost系统.但这些系统都不是微软原版的,制作者已经集成了很多常用软件或垃圾软件进去.我在这给大家介绍的是如何下载正版的Windows系统.这个 ...

  10. 7.17实习培训日志-java基础

    总结 今天主要是学习了java基础,java面向对象方面的知识,然后下午老师讲了软件的设计模式,今天看了一部分,印象深刻的是单例模式,用枚举实现单例模式.晚上主要讲了maven的一些基础知识和idea ...