HDU 1069 Monkey and Banana DP LIS变形题
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变形题的更多相关文章
- HDU 1069 Monkey and Banana DP LIS
http://acm.hdu.edu.cn/showproblem.php?pid=1069 题目大意 一群研究员在研究猴子的智商(T T禽兽啊,欺负猴子!!!),他们决定在房顶放一串香蕉,并且给猴子 ...
- hdu(1069)——Monkey and Banana(LIS变形)
题意: 如今给你n个石块,然后它由坐标来表示(x,y,z).可是它能够有不同的方法,也就是说它的三个坐标能够轮换着来的. 石块的数量不限,可是每次都必须保持上底面的长和宽严格递减,然后问你用这些石块所 ...
- HDU 1069 monkey an banana DP LIS
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription 一组研究人员正在 ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069 Monkey and Banana(DP 长方体堆放问题)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
- HDU 1069 Monkey and Banana(LIS最长上升子序列)
B - LIS Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descripti ...
- 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 ...
- HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
随机推荐
- [acm]HDOJ 2673 shǎ崽 OrOrOrOrz
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=2673 拍两次序,交替输出 #include<iostream> #include< ...
- 【LeetCode】047. Permutations II
题目: Given a collection of numbers that might contain duplicates, return all possible unique permutat ...
- 关闭windows10自动更新
用windows10的小伙伴们应该都被windows10自动更新这个问题折磨过.那到底要这样禁止windows10的自动更新呢? 百度上有一篇文章写的非常好,并且有配套,大家只要根据步骤操作即可,本人 ...
- QT(2)项目文件介绍
一.项目创建 二.文件说明 三.QT模块
- BZOJ2006:[NOI2010]超级钢琴
浅谈\(RMQ\):https://www.cnblogs.com/AKMer/p/10128219.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...
- hive 面试题
使用 Hive或者自定义 MR 实现如下逻辑 product_no lac_id moment start_time user_id county_id staytime city_id 134291 ...
- 使用maven导入任意jar包
http://mvnrepository.com/ 我这里,因为是spark1.5.2版本. 保存,maven会自动下载jar包到本地仓库.
- 5. 通过PHP反序列化进行远程代码执行
php序列化与反序列化 最近准备复现一下ecshop2.x,3.x的注入漏洞,其中涉及到了php反序列化的问题,由于之前太小白 ,导致粗心大意,所以此对php反序列化漏洞进行更详细的分析. 提起php ...
- Swoole 协程 MySQL 客户端与异步回调 MySQL 客户端的对比
Swoole 协程 MySql 客户端与 异步回调 MySql 客户端的对比 为什么要对比这两种不同模式的客户端? 异步 MySQL 回调客户端是虽然在 Swoole 1.8.6 版本就已经发布了, ...
- sqlserver2012——逻辑运算符
ALL 如果一组的比较都为TRUE,则结果为true ANY如果玉足比较中任何一个为true,则结果为true AND 两个boll都为TRUE,则结果为TRUE OR 两个BOLL任何一个TRUE, ...