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 ...
随机推荐
- 如何在u盘上安装系统, (非安装盘)
在u盘中永久安装Fedora. 需要两个u盘(live usb), 一个系统镜像文件. 方法是: 用一个u盘作安装盘, 然后通过这个u盘把系统安装到另一个u盘上. 两个U盘上的文件都会被覆盖. 1. ...
- P2743(poj1743) Musical Themes[差分+后缀数组]
P2743 乐曲主题Musical Themes(poj1743) 然后呢这题思路其实还是蛮简单的,只是细节特别多比较恶心,忘记了差分带来的若干疏漏.因为转调的话要保证找到相同主题,只要保证一段内相对 ...
- ACM学习历程—BestCoder 2015百度之星资格赛1003 IP聚合(set容器)
Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个网络地址.网 ...
- 开发工作之外的修炼Live笔记
“开发工作之外的修炼”这期Live分享了下列话题: [1] 如何发现自己的兴趣 [2] 财富.资源与被动收入 [3] 目标管理 [4] 快速做选择 [5] 时间管理 [6] 如何投资自己 >&g ...
- XCode工程中 Project 和 Targets区别
转自:http://blog.csdn.net/zhaozy55555/article/details/8557175 project就是一个项目,或者说工程,一个project可以对应多个targe ...
- java 通过System.getProperties()获取系统参数
转自:https://www.cnblogs.com/ksuifeng/archive/2010/09/25/1834416.html 1.java的System.getProperty()方法可以获 ...
- js中关于事件捕获与事件冒泡的小实验
1.事件冒泡:事件按照从最特定的事件目标到最不特定的事件目标(document对象)的顺序触发. IE 5.5: div -> body -> document IE 6.0: div - ...
- AngularJs(Part 4)--Modules depending on other Modules
Angular does an excellent job of managing object dependencies. it can even take care of module depen ...
- François Hollande’s&…
EVER since President François Hollande was elected last May, things have not gone right for him. He ...
- POJ 1127 Jack Straws (线段相交)
题意:给定一堆线段,然后有询问,问这两个线段是不是相交,并且如果间接相交也可以. 析:可以用并查集和线段相交来做,也可以用Floyd来做,相交就是一个模板题. 代码如下: #pragma commen ...