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. listen 78

    Struggling Young Readers Like Kindles Kindles, Nooks and other e-readers catch flack for threatening ...

  2. C语言中mktime函数功能及用法

    今天联系写一个日历的程序,需要算出月份中的第一天是星期几,用到了mktime()这个函数,感觉这个函数挺有用的,分享给大家. 原型:time_t mktime(struct tm *) 其中的tm结构 ...

  3. manacher(无讲解)

    BZOJ3325: [Scoi2013]密码 https://lydsy.com/JudgeOnline/problem.php?id=3325 分析: 根据前i个字符和一些不等和相等条件就可以确定每 ...

  4. ACM学习历程—HDU1028 Ignatius and the Princess(组合数学)

    Ignatius and the Princess Description        "Well, it seems the first problem is too easy. I w ...

  5. ACM学习历程——HDU 5014 Number Sequence (贪心)(2014西安网赛)

    Description There is a special number sequence which has n+1 integers. For each number in sequence, ...

  6. CAS单点登录学习(二):客户端配置

    下载jar包因为cas的源码修改变动很大,所以客户端引入的jar包根据服务端的war包而定.之前搭建的cas服务端用的版本是3.5.2,经过测试,可以使用cas-client-core的3.2.1版本 ...

  7. ICU 是一种说不出的痛啊

    USE [Nursing] GO /****** Object: StoredProcedure [dbo].[P_GetICUVitualSign] Script Date: 05/21/2015 ...

  8. Bind 远程连接出现rndc: connect failed: 192.168.1.66#953: connection refused

    远程连接IP地址为192.168.1.66的BIND DNS服务器,出现 rndc: connect failed: 192.168.1.66#953: connection refused 原因:1 ...

  9. SPFA算法——最短路径

    粗略讲讲SPFA算法的原理,SPFA算法是1994年西南交通大学段凡丁提出 是一种求单源最短路的算法 算法中需要用到的主要变量 int n;  //表示n个点,从1到n标号 int s,t;  //s ...

  10. backgroundWorker取消后,重新开始就报错:此 BackgroundWorker 当前正忙,无法同时运行多个任务。

    使用BackgroundWorker控件,有2个按钮buttonBegin和buttonCancel.其他都正常,只是在用buttonBegin开始运行,然后点击buttonCancel取消后,到这里 ...