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 ...
随机推荐
- T57
“期待使我产生了介于幸福与恐惧之间的激动”The anticipation produced in me a sensation somewhat between bliss and fear他猛一下 ...
- poj1733 Parity game[带权并查集or扩展域]
地址 连通性判定问题.(具体参考lyd并查集专题该题的转化方法,反正我菜我没想出来).转化后就是一个经典的并查集问题了. 带权:要求两点奇偶性不同,即连边权为1,否则为0,压缩路径时不断异或,可以通过 ...
- BZOJ3938:Robot
浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227.html 题目传送门:https://www.lydsy.com/JudgeOnline/proble ...
- poj3254二进制放牛——状态压缩DP
题目:http://poj.org/problem?id=3254 利用二进制压缩状态,每一个整数代表一行的01情况: 注意预处理出二进制表示下没有两个1相邻的数的方法,我的方法(不知为何)错了,看到 ...
- 人工智能实践:TensorFlow 框架
张量.计算图.会话 基本概念 基于Tensorflow的NN:用张量表示数据,用计算图搭建神经网络,用会话执行计算图,优化线上的权重(参数),得到模型. 张量(Tensor):张量就是多维数组(列表) ...
- POJ3264(线段树入门题)
Balanced LineupCrawling in process... Crawling failed Time Limit:5000MS Memory Limit:65536KB ...
- selenium+python中,框架中,怎么返回上一个菜单
/退回上一级表单 driver.switchTo().defaultContent();
- query builder 在线生成sql
http://devtools.korzh.com/easyquery/javascript/docs/javascript-query-builder-php
- c# 正则表达式移除html文本前面的空格
var val = Regex.Replace(text, @"^( | )+(?<value>.*)", "${value}", RegexOpt ...
- Process 启动参数问题
c#在有些情况下需要在启动另一个程序时传递参数,这里存在两个问题. 1.如果在参数里面含有空格,那么传递过去就会变成一个字符数组,这种情况是不满足情况的,解决方案是在传递参数时将空格用一些特殊字符替换 ...