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

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

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

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

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

思路:

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

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

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

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #define IOS ios::sync_with_stdio(false)
  7. using namespace std;
  8. #define inf (0x3f3f3f3f)
  9. typedef long long int LL;
  10.  
  11. #include <iostream>
  12. #include <sstream>
  13. #include <vector>
  14. #include <set>
  15. #include <map>
  16. #include <queue>
  17. #include <string>
  18. const int maxn = + ;
  19. int n;
  20. struct node {
  21. int L, W, H;
  22. node(int LL, int WW, int HH) : L(LL), W(WW), H(HH) {}
  23. node() {}
  24. bool operator < (const struct node & rhs) const {
  25. if (L != rhs.L) return L > rhs.L;
  26. else if (W != rhs.W) return W > rhs.W;
  27. else return H > rhs.H;
  28. }
  29. }a[maxn];
  30. int dp[maxn];
  31. bool isok(int one, int two) {
  32. if (a[one].L > a[two].L && a[one].W > a[two].W) return true;
  33. else return false;
  34. }
  35. void work () {
  36. int t = ;
  37. for (int i = ; i <= n; ++i) {
  38. int x, y, z;
  39. cin >> x >> y >> z;
  40. a[++t] = node(x, y, z);
  41. a[++t] = node(x, z, y);
  42. a[++t] = node(y, x, z);
  43. a[++t] = node(y, z, x);
  44. a[++t] = node(z, x, y);
  45. a[++t] = node(z, y, x);
  46. }
  47. sort(a + , a + + t);
  48. for (int i = ; i <= t; ++i) {
  49. dp[i] = a[i].H;
  50. for (int j = ; j < i; ++j) {
  51. if (isok(j, i)) {
  52. dp[i] = max(dp[i], dp[j] + a[i].H);
  53. }
  54. }
  55. }
  56. int ans = -inf;
  57. for (int i = ; i <= t; ++i) {
  58. ans = max(ans, dp[i]);
  59. }
  60. static int f = ;
  61. printf("Case %d: maximum height = %d\n", ++f, ans);
  62. }
  63.  
  64. int main() {
  65. #ifdef local
  66. freopen("data.txt","r",stdin);
  67. #endif
  68. // IOS;
  69. while (cin >> n && n) work();
  70. return ;
  71. }

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. 如何在u盘上安装系统, (非安装盘)

    在u盘中永久安装Fedora. 需要两个u盘(live usb), 一个系统镜像文件. 方法是: 用一个u盘作安装盘,  然后通过这个u盘把系统安装到另一个u盘上. 两个U盘上的文件都会被覆盖. 1. ...

  2. P2743(poj1743) Musical Themes[差分+后缀数组]

    P2743 乐曲主题Musical Themes(poj1743) 然后呢这题思路其实还是蛮简单的,只是细节特别多比较恶心,忘记了差分带来的若干疏漏.因为转调的话要保证找到相同主题,只要保证一段内相对 ...

  3. ACM学习历程—BestCoder 2015百度之星资格赛1003 IP聚合(set容器)

    Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个网络地址.网 ...

  4. 开发工作之外的修炼Live笔记

    “开发工作之外的修炼”这期Live分享了下列话题: [1] 如何发现自己的兴趣 [2] 财富.资源与被动收入 [3] 目标管理 [4] 快速做选择 [5] 时间管理 [6] 如何投资自己 >&g ...

  5. XCode工程中 Project 和 Targets区别

    转自:http://blog.csdn.net/zhaozy55555/article/details/8557175 project就是一个项目,或者说工程,一个project可以对应多个targe ...

  6. java 通过System.getProperties()获取系统参数

    转自:https://www.cnblogs.com/ksuifeng/archive/2010/09/25/1834416.html 1.java的System.getProperty()方法可以获 ...

  7. js中关于事件捕获与事件冒泡的小实验

    1.事件冒泡:事件按照从最特定的事件目标到最不特定的事件目标(document对象)的顺序触发. IE 5.5: div -> body -> document IE 6.0: div - ...

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

  9. Fran&ccedil;ois&nbsp;Hollande’s&amp;…

    EVER since President François Hollande was elected last May, things have not gone right for him. He ...

  10. POJ 1127 Jack Straws (线段相交)

    题意:给定一堆线段,然后有询问,问这两个线段是不是相交,并且如果间接相交也可以. 析:可以用并查集和线段相交来做,也可以用Floyd来做,相交就是一个模板题. 代码如下: #pragma commen ...